Bug 855483 - allow2audit doesn't parse boot date correctly in all locales
allow2audit doesn't parse boot date correctly in all locales
Status: CLOSED ERRATA
Product: Fedora
Classification: Fedora
Component: policycoreutils (Show other bugs)
17
Unspecified Unspecified
unspecified Severity unspecified
: ---
: ---
Assigned To: Daniel Walsh
Fedora Extras Quality Assurance
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2012-09-07 21:40 EDT by Ian Dall
Modified: 2013-05-31 22:27 EDT (History)
4 users (show)

See Also:
Fixed In Version: policycoreutils-2.1.13-27.3.fc17
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2012-12-20 11:09:22 EST
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Ian Dall 2012-09-07 21:40:08 EDT
Description of problem:

allow2audit -b fails with "Error parsing start date" for non-north american locales. 

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

policycoreutils-python-2.1.11-18.fc17.x86_64

How reproducible:
Always.


Steps to Reproduce:
1. Arrange for boot time to be after the 12th day of the month
2. LC_ALL=en_AU.UTF-8 audit2allow -b 
3.
  
Actual results:
Error parsing start date (08/28/2012)

Expected results:
A list of suggested "allow" rules


Additional info:

LC_ALL=en_US.UTF-8 audit2allow -b

works.

It would seem that the boot date is always in mm/dd/yyyy format regardless of locale, but it is being parsed in the current locale which expects dd/mm/yyyy.
Comment 1 Daniel Walsh 2012-09-19 21:33:34 EDT
Steve does ausearch handle this properly?
Comment 2 Steve Grubb 2012-09-19 22:12:24 EDT
Ausearch does this in main() :
        /* Check params and build regexpr */
        setlocale (LC_ALL, "");

According to the man page:
       If locale is "", each part of the locale that should be modified is set
       according to the environment variables.

So, ausearch _should_ be OK. Does policycoreutils use ausearch or libauparse?
Comment 3 Ian Dall 2012-09-20 08:08:15 EDT
I'm not sure what would be the equivalent as there is no "since boot" option for ausearch. I can set -te or -ts putting the date in the en_AU locale format and it works properly and it all works properly.
Comment 4 Daniel Walsh 2012-09-26 17:37:00 EDT
def get_audit_boot_msgs():
    """Obtain all of the avc and policy load messages from the audit
    log. This function uses ausearch and requires that the current
    process have sufficient rights to run ausearch.

    Returns:
       string contain all of the audit messages returned by ausearch.
    """
    import subprocess
    import time
    fd=open("/proc/uptime", "r")
    off=float(fd.read().split()[0])
    fd.close
    s = time.localtime(time.time() - off)
    date = time.strftime("%D/%Y", s).split("/")
    bootdate="%s/%s/%s" % (date[0], date[1], date[3])
    boottime = time.strftime("%X", s)
    output = subprocess.Popen(["/sbin/ausearch", "-m", "AVC,USER_AVC,MAC_POLICY_LOAD,DAEMON_START,SELINUX_ERR", "-ts", bootdate, boottime],
                              stdout=subprocess.PIPE).communicate()[0]
    return output

This is the python code that we are calling.
Comment 5 Ian Dall 2012-09-26 19:15:39 EDT
So how about:

    bootdate = time.strftime("%x", s)

instead of

    date = time.strftime("%D/%Y", s).split("/")
    bootdate="%s/%s/%s" % (date[0], date[1], date[3])

At least in my locale, the year is in 2 digit format, so this would fail
if the boot date it before a century boundary boundary, but otherwise should work.
Comment 6 Daniel Walsh 2012-10-16 15:06:56 EDT
Fixed in 
policycoreutils-2.1.12-4.fc17
Comment 7 Fedora Update System 2012-10-24 09:04:58 EDT
policycoreutils-2.1.12-4.fc17 has been submitted as an update for Fedora 17.
https://admin.fedoraproject.org/updates/policycoreutils-2.1.12-4.fc17
Comment 8 Fedora Update System 2012-10-24 19:56:53 EDT
Package policycoreutils-2.1.12-4.fc17:
* should fix your issue,
* was pushed to the Fedora 17 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing policycoreutils-2.1.12-4.fc17'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2012-16848/policycoreutils-2.1.12-4.fc17
then log in and leave karma (feedback).
Comment 9 Fedora Update System 2012-10-31 21:25:38 EDT
Package policycoreutils-2.1.12-5.fc17:
* should fix your issue,
* was pushed to the Fedora 17 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing policycoreutils-2.1.12-5.fc17'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2012-16848/policycoreutils-2.1.12-5.fc17
then log in and leave karma (feedback).
Comment 10 Scott Shambarger 2012-12-06 18:29:36 EST
policycoreutils-2.1.12-5.fc17 breaks on my system.  Running "audit2allow -b" results in:

Error - year is 12

Tracked the problem down to the date string generated with above fix... which resulted in the following ausearch call:

/sbin/ausearch -m AVC,USER_AVC,MAC_POLICY_LOAD,DAEMON_START,SELINUX_ERR -ts 12/06/12 14:45:43

My LANG environment (set on the kernel commandline and in /etc/locale.conf) is:

LANG=en_US.UTF-8

Modifying the LANG to something other than UTF-8 works around the issue, eg:

LANG=en_US.en_AU audit2allow -b

... works.
Comment 11 Daniel Walsh 2012-12-07 10:56:02 EST
We have fixed this in the F18 code base.
Comment 12 Scott Shambarger 2012-12-12 20:35:43 EST
Any chance of getting this backported?  Most people probably won't discover the LANG workaround in F17...
Comment 13 Daniel Walsh 2012-12-17 15:27:53 EST
Just check if adding these lines to /usr/bin/audit2allow fixes the problem.

diff -u audit2allow /usr/bin/audit2allow  
--- audit2allow	2012-09-25 16:17:37.000000000 -0400
+++ /usr/bin/audit2allow	2012-12-10 11:10:12.000000000 -0500
@@ -29,6 +29,8 @@
 import sepolgen.module as module
 from sepolgen.sepolgeni18n import _
 import selinux.audit2why as audit2why
+import locale
+locale.setlocale(locale.LC_ALL, '')
 
 class AuditToPolicy:
     VERSION = "%prog .1"
[Exit 1]
Comment 14 Scott Shambarger 2012-12-18 02:05:03 EST
Yep, tried the patch and both audit2allow and audit2why work as expected.
Comment 15 Daniel Walsh 2012-12-18 08:52:14 EST
Fixed in policycoreutils-2.1.13-27.1.fc17
Comment 16 Fedora Update System 2012-12-18 08:54:03 EST
policycoreutils-2.1.13-27.1.fc17 has been submitted as an update for Fedora 17.
https://admin.fedoraproject.org/updates/policycoreutils-2.1.13-27.1.fc17
Comment 17 Scott Shambarger 2012-12-18 20:16:50 EST
Updated to 2.1.13-27.1 - audit2allow works great :)

Added karma on fedoraproject.
Comment 18 Fedora Update System 2012-12-20 11:09:24 EST
policycoreutils-2.1.12-5.fc17 has been pushed to the Fedora 17 stable repository.  If problems still persist, please make note of it in this bug report.
Comment 19 Fedora Update System 2013-01-25 08:23:05 EST
policycoreutils-2.1.13-27.2.fc17 has been submitted as an update for Fedora 17.
https://admin.fedoraproject.org/updates/policycoreutils-2.1.13-27.2.fc17
Comment 20 Fedora Update System 2013-02-08 14:29:06 EST
policycoreutils-2.1.13-27.3.fc17 has been submitted as an update for Fedora 17.
https://admin.fedoraproject.org/updates/policycoreutils-2.1.13-27.3.fc17
Comment 21 Fedora Update System 2013-05-31 22:27:17 EDT
policycoreutils-2.1.13-27.3.fc17 has been pushed to the Fedora 17 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.