Bug 1079534 - SELinux is preventing /usr/bin/grep from using the 'execmem' accesses on a process.
Summary: SELinux is preventing /usr/bin/grep from using the 'execmem' accesses on a pr...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: selinux-policy
Version: rawhide
Hardware: x86_64
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Miroslav Grepl
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard: abrt_hash:ea56b621e6ae4663a3847103413...
: 1094077 1097300 (view as bug list)
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-03-21 18:47 UTC by Joachim Frieben
Modified: 2014-06-16 23:27 UTC (History)
36 users (show)

Fixed In Version: cups-filters-1.0.53-5.fc20
Clone Of:
Environment:
Last Closed: 2014-06-16 23:27:24 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)
description with selinux 3.13.1-55 (2.15 KB, text/plain)
2014-06-06 16:17 UTC, Raphael Groner
no flags Details

Description Joachim Frieben 2014-03-21 18:47:36 UTC
Description of problem:
SELinux is preventing /usr/bin/grep from using the 'execmem' accesses on a process.

*****  Plugin catchall (100. confidence) suggests   **************************

If you believe that grep should be allowed execmem access on processes labeled cupsd_t by default.
Then you should report this as a bug.
You can generate a local policy module to allow this access.
Do
allow this access for now by executing:
# grep grep /var/log/audit/audit.log | audit2allow -M mypol
# semodule -i mypol.pp

Additional Information:
Source Context                system_u:system_r:cupsd_t:s0-s0:c0.c1023
Target Context                system_u:system_r:cupsd_t:s0-s0:c0.c1023
Target Objects                 [ process ]
Source                        grep
Source Path                   /usr/bin/grep
Port                          <Unknown>
Host                          (removed)
Source RPM Packages           grep-2.18-1.fc21.x86_64
Target RPM Packages           
Policy RPM                    selinux-policy-3.13.1-38.fc21.noarch
Selinux Enabled               True
Policy Type                   targeted
Enforcing Mode                Permissive
Host Name                     (removed)
Platform                      Linux (removed) 3.14.0-0.rc7.git0.1.fc21.x86_64 #1
                              SMP Mon Mar 17 13:48:26 UTC 2014 x86_64 x86_64
Alert Count                   1
First Seen                    2014-03-21 19:46:20 CET
Last Seen                     2014-03-21 19:46:20 CET
Local ID                      f4fb849c-a7ba-4ee5-8e6a-0ec22d235738

Raw Audit Messages
type=AVC msg=audit(1395427580.543:403): avc:  denied  { execmem } for  pid=2848 comm="grep" scontext=system_u:system_r:cupsd_t:s0-s0:c0.c1023 tcontext=system_u:system_r:cupsd_t:s0-s0:c0.c1023 tclass=process


type=SYSCALL msg=audit(1395427580.543:403): arch=x86_64 syscall=mmap success=yes exit=139959619260416 a0=0 a1=10000 a2=7 a3=22 items=0 ppid=2819 pid=2848 auid=4294967295 uid=4 gid=7 euid=4 suid=4 fsuid=4 egid=7 sgid=7 fsgid=7 tty=(none) ses=4294967295 comm=grep exe=/usr/bin/grep subj=system_u:system_r:cupsd_t:s0-s0:c0.c1023 key=(null)

Hash: grep,cupsd_t,cupsd_t,process,execmem

Additional info:
reporter:       libreport-2.2.0
hashmarkername: setroubleshoot
kernel:         3.14.0-0.rc7.git0.1.fc21.x86_64
type:           libreport

Comment 1 Daniel Walsh 2014-03-22 10:29:18 UTC
This is very strange AVC.  There is no reason for grep or cups to need execmem privilege.

Comment 2 Miroslav Grepl 2014-05-05 09:17:29 UTC
*** Bug 1094077 has been marked as a duplicate of this bug. ***

Comment 3 fred 2014-05-08 06:30:56 UTC
Description of problem:
Impression d'un document (cups)

Additional info:
reporter:       libreport-2.2.2
hashmarkername: setroubleshoot
kernel:         3.14.2-200.fc20.x86_64
type:           libreport

Comment 4 David Anderson 2014-05-09 13:57:07 UTC
I get this too. I Googled it because I was also surprised to see grep wanting to  execmem.

Christoph, Fred, what's your printer? Mine's an HP that has a binary plugin (that is installed by hp-toolbox). Does yours have a binary plugin too?

Comment 5 David Anderson 2014-05-09 13:59:52 UTC
Also: in the duplicate (#1079534), the description says "Attempted to print to a remote CUPS server". This present bug does not state whether the CUPS server was remote. In my case, it is on localhost.

Comment 6 fred 2014-05-10 13:27:13 UTC
My printer is an Epson Stylus C84. 
It's not a remote printer.

Comment 7 klaus 2014-05-12 09:22:45 UTC
Description of problem:
Trying to print from Okular

Additional info:
reporter:       libreport-2.2.2
hashmarkername: setroubleshoot
kernel:         3.14.2-200.fc20.x86_64
type:           libreport

Comment 8 Tim Waugh 2014-05-12 11:30:21 UTC
This comes from pcre. Not sure if there's a way for grep to tell it not to do that.

Several print filters use grep.

Probably the best thing is for this to be allowed in the policy.

Comment 9 John Freed 2014-05-14 08:23:48 UTC
Description of problem:
tried to make a printout to a remote printer

Additional info:
reporter:       libreport-2.2.2
hashmarkername: setroubleshoot
kernel:         3.14.2-200.fc20.x86_64
type:           libreport

Comment 10 Gregor Hlawacek 2014-05-15 08:59:23 UTC
Description of problem:
Nothing special just printed from Word using cross over office

Additional info:
reporter:       libreport-2.2.2
hashmarkername: setroubleshoot
kernel:         3.14.3-200.fc20.x86_64
type:           libreport

Comment 11 Johan Vervloet 2014-05-16 08:43:46 UTC
Description of problem:
This was the command that triggered the problem:

ls some/path/*.inc | a2ps -P my_printer

Additional info:
reporter:       libreport-2.2.2
hashmarkername: setroubleshoot
kernel:         3.14.3-200.fc20.x86_64
type:           libreport

Comment 12 Daniel Walsh 2014-05-17 10:04:13 UTC
Tim you are saying libpcre requies execmem privs now?

Comment 13 fedorino-core 2014-05-18 09:41:43 UTC
Description of problem:
I have got this error message after installing HP-printer driver from hplipopensource.com/hplip-web/install/install/index.html , according their instruction. 

Additional info:
reporter:       libreport-2.2.2
hashmarkername: setroubleshoot
kernel:         3.14.4-200.fc20.x86_64
type:           libreport

Comment 14 fedinux25 2014-05-19 08:33:25 UTC
Description of problem:
hi! :-)

when i want to use my hp deskjet 2540 serie by wifi, selinux block her.

before i add fedora 20 , it was fedora 19 and it run very good.

the log:
Vous devriez rapporter ceci en tant qu'anomalie.
Vous pouvez générer un module de stratégie local pour autoriser cet accès.
Autoriser cet accès pour le moment en exécutant :
# grep grep /var/log/audit/audit.log | audit2allow -M mypol
# semodule -i mypol.pp

Additional info:
reporter:       libreport-2.2.2
hashmarkername: setroubleshoot
kernel:         3.14.4-200.fc20.i686
type:           libreport

Comment 15 Tim Waugh 2014-05-19 10:42:45 UTC
(In reply to Daniel Walsh from comment #12)
> Tim you are saying libpcre requies execmem privs now?

Just observing that grep doesn't use PROT_EXEC in mmap(), but libpcre does.

Looks similar to bug #923516?

Comment 16 Petr Pisar 2014-05-19 11:39:29 UTC
PCRE library can use JIT for matching regular expression since version 8.21 (first in Fedora 17). By default not JIT is used. Application has to ask for it explicitly with pcre_study(, PCRE_STUDY_JIT_COMPILE, ) and then allocating the JIT stack by pcre_jit_stack_alloc() and registering it to the context by pcre_assign_jit_stack(). Please note the JIT is not used all the time a application request it. Some regular expressions are not implemented in JIT, thus PCRE library can decide to fall to the interpreter path back. See pcrejit(3) for more details.

grep-2.18 as can be found in Fedora 21 does that (src/pcresearch.c).

a2ps does use PCRE library directly. It executes grep(1).

Decision whether a JIT will be used is a run-time matter. It's up to applications.

Comment 17 Tim Waugh 2014-05-19 12:42:15 UTC
Does grep have a runtime switch for not using JIT?

Comment 18 Petr Pisar 2014-05-19 12:55:24 UTC
grep does not PCRE by default. However if run with `-P' option, it will use PCRE and it will enable JIT. There is no switch to disable the JIT currently.

Comment 19 Tim Waugh 2014-05-19 13:18:12 UTC
Could anyone experiencing this bug please try 'yum downgrade grep' and see if the problem still occurs?

That would help to determine if it really is coming from the changes in the new version of grep.

Comment 20 Tim Waugh 2014-05-19 14:07:30 UTC
*** Bug 1097300 has been marked as a duplicate of this bug. ***

Comment 21 klaus 2014-05-19 14:28:40 UTC
(In reply to Tim Waugh from comment #19)
> Could anyone experiencing this bug please try 'yum downgrade grep' and see
> if the problem still occurs?
> 
> That would help to determine if it really is coming from the changes in the
> new version of grep.

I just tried to downgrade grep. Problem persists.

|<

Comment 22 Tim Waugh 2014-05-19 15:39:09 UTC
SELinux says that grep is doing this. Does the maintainer have any idea why grep would need 'execmem' in any situation?

Comment 23 Karel Volný 2014-05-19 21:13:32 UTC
Description of problem:
I just tried to send two pages to printer from Okular ...

Additional info:
reporter:       libreport-2.2.2
hashmarkername: setroubleshoot
kernel:         3.14.4-200.fc20.x86_64
type:           libreport

Comment 24 Petr Pisar 2014-05-20 05:29:25 UTC
(In reply to Tim Waugh from comment #22)
> SELinux says that grep is doing this. Does the maintainer have any idea why
> grep would need 'execmem' in any situation?

This has nothing to do with libpcre or grep. This is a bug in SELinux policy. Just any process which executes "grep -P" can run into the JIT code. The code resides in libpcre and it does mmap(PROT_EXEC).

The problem is SELinux policy binds permissions to process domains which are bound to executed programs. AFAIK SELinux cannot track shared libraries linked into the executed program. So there is no way to declare that any program linked to libpcre is allowed to do "execmem". Instead the policy needs to enumerate each programs which executes grep.

Therefore the only workaround here is to create a new domain for /usr/bin/grep and allow "execmem" there. And then allow the transition from daemons domain there.

Comment 25 Daniel Walsh 2014-05-25 10:24:09 UTC
Well this is the only time we have ever seen an AVC about grep doing execmem.

       -P, --perl-regexp
              Interpret PATTERN as a Perl regular expression.  This is  highly
              experimental and grep -P may warn of unimplemented features.


Does not seem like this is likely to happen often.

Simplest thing is to allow cups to do execmem.  Perhaps via boolean.

Comment 26 Karel Volný 2014-05-26 21:11:50 UTC
Description of problem:
I just printed a few pages ... this one should end up as duplicate, sending just to update the version - still a problem with
cups-1.7.2-1.fc20.x86_64
cups-filters-1.0.53-2.fc20.x86_64
foomatic-4.0.9-6.fc20.x86_64

Additional info:
reporter:       libreport-2.2.2
hashmarkername: setroubleshoot
kernel:         3.14.4-200.fc20.x86_64
type:           libreport

Comment 27 John Sauter 2014-06-02 11:06:44 UTC
Description of problem:
I was using  a2ps -1 to print a small file on my HP 8700 printer.

Additional info:
reporter:       libreport-2.2.2
hashmarkername: setroubleshoot
kernel:         3.14.4-200.fc20.x86_64
type:           libreport

Comment 28 Peter Greenwood 2014-06-02 18:12:24 UTC
Description of problem:
Problem occurred using xsane in "copy"mode, copying from HP scanner to (separate) HP printer.

Additional info:
reporter:       libreport-2.2.2
hashmarkername: setroubleshoot
kernel:         3.14.3-200.fc20.x86_64
type:           libreport

Comment 29 Petr Pisar 2014-06-03 04:53:46 UTC
(In reply to Daniel Walsh from comment #25)
> Simplest thing is to allow cups to do execmem.  Perhaps via boolean.

Moving back to SELinux policy component.

Comment 30 Raphael Groner 2014-06-04 06:03:31 UTC
I see this only when I print from SoftMaker but not when printing a PDF.

Comment 31 Miroslav Grepl 2014-06-06 12:11:29 UTC
commit a315fce1314d0fc74d7632d08430eb6bd01ce1a4
Author: Miroslav Grepl <mgrepl>
Date:   Fri Jun 6 14:10:44 2014 +0200

    Add cups_execmem boolean

Comment 32 John Freed 2014-06-06 12:40:04 UTC
I think this is an incorrect "solution" to this problem.

I don't understand why the "experimental" -p switch in grep is using execmem, when in fact Perl itself does not do so. It strikes me as an entirely insecure, even dangerous, usage. And I'm grateful that SELinux caught it.

Why CUPS is using this experimental switch is also a mystery to me.

It would be far better for the people working on CUPS and grep to explain what is going on, rather than offering a potentially disastrous security hole into SELinux. I can understand why WINE/Microsoft Windows requires execmem, but not CUPS or grep.

Comment 33 Petr Pisar 2014-06-06 13:21:40 UTC
(In reply to John Freed from comment #32)
> I don't understand why the "experimental" -p switch in grep is using
> execmem,

Because -P stands for "use PCRE semantics and PCRE library" and, in addition, grep enables JIT in the PCRE library. Thus PCRE library needs execmem permission.

> when in fact Perl itself does not do so.

Perl does not do JIT.

> Why CUPS is using this experimental switch is also a mystery to me.
> 
Because it's faster?

Comment 34 David Anderson 2014-06-06 13:27:54 UTC
Would not the optimal solution be if grep was able to both a) use PCRE and b) not use JIT? Perhaps with a new switch, e.g. --no-pcre-jit ... and then to patch everywhere in CUPS that is calling grep to use that switch?

From a usability point-of-view, having a cups_execmem boolean seems a bit like pushing the hard decision onto the ill-equipped user.

From a security point-of-view, allowing a program that potentially receives remote user-controlled input (e.g. network office printing) to have the ability to execmem seems worrying, especially when (from this ticket so far), the exact vectors through which input gets passed through from cups to grep seem not to be known yet.

Is the cups_execmem boolean at this point just a renamed "not_really_understood_lower_your_security_if_you_want_its_your_risk" boolean, or is this problem better understood than the comments in this ticket imply so far?

Comment 35 John Freed 2014-06-06 13:59:07 UTC
Thank you David Anderson for expressing this better than I could.

Petr, "faster but insecure" is not a solution. If it is in fact several orders of magnitude faster, I might agree, but I have seen no groundswell of demand for such a change -- none at all in fact. I have never noticed a speed problem with CUPS. The horrendous potential security hole, on the other hand, is obvious (and trapped by SELinux).

Comment 36 Raphael Groner 2014-06-06 14:34:07 UTC
(In reply to Miroslav Grepl from comment #31)
> commit a315fce1314d0fc74d7632d08430eb6bd01ce1a4
> Author: Miroslav Grepl <mgrepl>
> Date:   Fri Jun 6 14:10:44 2014 +0200
> 
>     Add cups_execmem boolean

Please patch for Fedora 20 as well. Thanks.

Comment 37 Tim Waugh 2014-06-06 16:08:31 UTC
I think I have have tracked down the culprit: /usr/lib/cups/filter/pstopdf, from the cups-filters package.

I was never able to reproduce the AVC here. Would someone be able to verify whether this package fixes it?:
http://koji.fedoraproject.org/koji/buildinfo?buildID=521544

Comment 38 Raphael Groner 2014-06-06 16:16:04 UTC
Sorry, but the abrt report did not disappear.

selinux-policy-3.13.1-55.fc20.noarch
selinux-policy-targeted-3.13.1-55.fc20.noarch
selinux-policy-devel-3.13.1-55.fc20.noarch

I'll attach a new description file.

Comment 39 Raphael Groner 2014-06-06 16:17:26 UTC
Created attachment 902970 [details]
description with selinux 3.13.1-55

This happened with a koji scratch build from the fc21 source rpm.

selinux-policy-3.13.1-55.fc20.noarch
selinux-policy-targeted-3.13.1-55.fc20.noarch
selinux-policy-devel-3.13.1-55.fc20.noarch

Comment 40 Miroslav Grepl 2014-06-06 16:44:52 UTC
Sure, please see the "Fixed In Version" field.

selinux-policy-3.13.1-56.fc21

Comment 41 Raphael Groner 2014-06-06 17:05:11 UTC
(In reply to Miroslav Grepl from comment #40)
> selinux-policy-3.13.1-56.fc21

Oh, sorry for this wasted noise. I did not notice that only the patch # has increased. I'll wait for an official new package.

Comment 42 Petr Pisar 2014-06-09 06:22:41 UTC
(In reply to John Freed from comment #35)
> Thank you David Anderson for expressing this better than I could.
> 
> "faster but insecure"

That says you.

> speed problem with CUPS. The horrendous potential security hole, on the
> other hand, is obvious (and trapped by SELinux).

I proposed creating new domain specifically for grep. Not allowing whole cupsd to have executable heap as it was implemented by the update. Also please note that the thing which is executed is not a network input (the printed page), but a regular expression which is a static argument. And just for your information, there are numerous binaries with JIT: Javascript engines, Java, Haskell, or Prolog interpreters, OpenGL implementations etc. Even the modern Linux packet filter is JITted. Today's software is such a horrendously insecure.

Comment 43 Daniel Walsh 2014-06-09 11:25:23 UTC
I agree with David that we really need a way to tell grep not to use this.  Writing a transition rule for something like grep is rather difficult policy writing and brings little benefit.

Allowing JIT for user sessions is a fact of life, but allowing it for system services, so far has not been that big of a problem.  I have seen few instances where services need this access.

Comment 44 Joseph Yaworski 2014-06-11 01:19:00 UTC
Description of problem:
The problem happens every time I try to print. Specifically from Okular. My files still printed, but this AVC denial persists.

Additional info:
reporter:       libreport-2.2.2
hashmarkername: setroubleshoot
kernel:         3.14.6-200.fc20.x86_64
type:           libreport

Comment 45 Fedora Update System 2014-06-11 15:57:38 UTC
cups-filters-1.0.53-4.fc20 has been submitted as an update for Fedora 20.
https://admin.fedoraproject.org/updates/cups-filters-1.0.53-4.fc20

Comment 46 Randy Berry 2014-06-11 20:17:39 UTC
Description of problem:
Printing from browser

Additional info:
reporter:       libreport-2.2.2
hashmarkername: setroubleshoot
kernel:         3.14.5-200.fc20.i686+PAE
type:           libreport

Comment 47 Fedora Update System 2014-06-12 06:28:06 UTC
Package cups-filters-1.0.53-4.fc20:
* should fix your issue,
* was pushed to the Fedora 20 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing cups-filters-1.0.53-4.fc20'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2014-7297/cups-filters-1.0.53-4.fc20
then log in and leave karma (feedback).

Comment 48 John Freed 2014-06-12 23:44:50 UTC
Still getting AVC. Unless I am making some sort of error, line 108 of pstopdf reads:

if printf "%s" "$5" | grep -iPq '(\s|^)landscape(=(1|on|yes|true))?(\s|$)'; then


and thus still uses grep -P

Comment 49 Tim Waugh 2014-06-13 09:24:42 UTC
Thanks for spotting that. The patch hadn't been applied in the spec file. :-(

cups-filters-1.0.53-5.fc20 should fix it.

Comment 50 John Freed 2014-06-13 10:06:58 UTC
Perfect! Thanks, Tim Waugh.

Here's hoping the premature boolean introduced in Comment #31 can be reversed.

Comment 51 John Freed 2014-06-13 10:14:02 UTC
Petr, thanks for your explanation in comment #42 that it's just using the static argument and not the network input. That's reassuring.

Comment 52 Fedora Update System 2014-06-13 22:50:50 UTC
Package cups-filters-1.0.53-5.fc20:
* should fix your issue,
* was pushed to the Fedora 20 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing cups-filters-1.0.53-5.fc20'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2014-7297/cups-filters-1.0.53-5.fc20
then log in and leave karma (feedback).

Comment 53 Fedora Update System 2014-06-16 23:27:24 UTC
cups-filters-1.0.53-5.fc20 has been pushed to the Fedora 20 stable repository.  If problems still persist, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.