RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1988339 - HTTP script cannot send mails due to sendmail not being able to read on stdin
Summary: HTTP script cannot send mails due to sendmail not being able to read on stdin
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: selinux-policy
Version: 8.4
Hardware: All
OS: Linux
medium
medium
Target Milestone: rc
: 8.6
Assignee: Zdenek Pytela
QA Contact: Amith
URL:
Whiteboard:
Depends On:
Blocks: 2049372
TreeView+ depends on / blocked
 
Reported: 2021-07-30 10:35 UTC by Renaud Métrich
Modified: 2024-10-01 19:06 UTC (History)
4 users (show)

Fixed In Version: selinux-policy-3.14.3-89.el8
Doc Type: No Doc Update
Doc Text:
Clone Of:
: 2049372 (view as bug list)
Environment:
Last Closed: 2022-05-10 15:14:58 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Knowledge Base (Solution) 6241331 0 None None None 2021-08-05 09:12:44 UTC
Red Hat Product Errata RHBA-2022:1995 0 None Waiting on Customer noProxy変更後一部Podが起動してこない 2022-05-13 01:53:51 UTC

Description Renaud Métrich 2021-07-30 10:35:35 UTC
Description of problem:

There is a boolean to let HTTPD scripts send mails: httpd_can_sendmail
Even with this booleans, cgi-bin scripts cannot send mails in the end because sendmail is not able to read the mail on standard input, the mail being a (deleted) temporary file labeled with httpd_sys_rw_content_t. This ends up having an empty mail being sent.

Version-Release number of selected component (if applicable):

selinux-policy-3.14.3-67.el8.noarch, also seen on RHEL7

How reproducible:

Always

Steps to Reproduce:
1. Create a cgi-bin script that sends mail

/var/www/cgi-bin/test.sh:
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
#!/bin/sh

cat << EOF
Content-type: text/html

EOF

exec /usr/local/bin/testmail.sh
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

/usr/local/bin/testmail.sh:
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
#!/bin/bash
echo "$(basename $0): $(id -Z)"
echo "testmail.sh" | mail -r root@localhost -s "testmail" -a /var/www/html/foo root@localhost
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

# echo "FOO" > /var/www/html/foo
# chmod +x /usr/local/bin/testmail.sh /var/www/cgi-bin/test.sh
# restorecon -Frv /var/www/html/foo /usr/local/bin/testmail.sh /var/www/cgi-bin/test.sh

2. Start httpd and call the cgi-bin script

# systemctl start httpd
# curl http://localhost/cgi-bin/test.sh
testmail.sh: system_u:system_r:httpd_sys_script_t:s0

3. Check the mail content


Actual results:

# mail
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/spool/mail/root": 1 message 1 unread
>U  1 Apache                Fri Jul 30 12:30  11/401   
& 
Message  1:
From root@localhost  Fri Jul 30 12:30:33 2021
Return-Path: <root@localhost>
X-Original-To: root@localhost
Delivered-To: root@localhost
Date: Fri, 30 Jul 2021 12:30:33 +0200 (CEST)
From: Apache <root@localhost>
Status: RO


# ausearch -m avc -ts recent -i
----
type=PROCTITLE msg=audit(07/30/2021 12:30:33.200:1256) : proctitle=send-mail -i -r root@localhost -- root@localhost 
type=EXECVE msg=audit(07/30/2021 12:30:33.200:1256) : argc=6 a0=send-mail a1=-i a2=-r a3=root@localhost a4=-- a5=root@localhost 
type=SYSCALL msg=audit(07/30/2021 12:30:33.200:1256) : arch=x86_64 syscall=execve success=yes exit=0 a0=0x5567599af3d2 a1=0x55675bb709d0 a2=0x7ffd9bad6ac0 a3=0x8 items=0 ppid=1 pid=6046 auid=unset uid=apache gid=apache euid=apache suid=apache fsuid=apache egid=apache sgid=apache fsgid=apache tty=(none) ses=unset comm=sendmail exe=/usr/sbin/sendmail.postfix subj=system_u:system_r:system_mail_t:s0 key=(null) 
type=AVC msg=audit(07/30/2021 12:30:33.200:1256) : avc:  denied  { read } for  pid=6046 comm=sendmail path=/tmp/RsHEeyJh (deleted) dev="dm-0" ino=52299521 scontext=system_u:system_r:system_mail_t:s0 tcontext=system_u:object_r:httpd_sys_rw_content_t:s0 tclass=file permissive=0 


Expected results:

Non-empty mail + no AVC


Additional info:

The issue is due to having the mail command (running as httpd_sys_script_t) create a temporary file in /tmp (of httpd service) as httpd_sys_rw_content_t because of the automatic transition in the policy.
This temporary file is used as stdin for sendmail command, which runs as system_mail_t but the file cannot be read due to missing rules in the policy.

Comment 1 Zdenek Pytela 2022-01-25 19:57:11 UTC
I've submitted a Fedora PR to address the issue:
https://github.com/fedora-selinux/selinux-policy/pull/1026

Comment 9 errata-xmlrpc 2022-05-10 15:14:58 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (selinux-policy bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2022:1995


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