Bug 855483 - allow2audit doesn't parse boot date correctly in all locales
Summary: allow2audit doesn't parse boot date correctly in all locales
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: policycoreutils
Version: 17
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Daniel Walsh
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2012-09-08 01:40 UTC by Ian Dall
Modified: 2013-06-01 02:27 UTC (History)
4 users (show)

Fixed In Version: policycoreutils-2.1.13-27.3.fc17
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2012-12-20 16:09:22 UTC
Type: Bug


Attachments (Terms of Use)

Description Ian Dall 2012-09-08 01:40:08 UTC
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-20 01:33:34 UTC
Steve does ausearch handle this properly?

Comment 2 Steve Grubb 2012-09-20 02:12:24 UTC
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 12:08:15 UTC
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 21:37:00 UTC
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 23:15:39 UTC
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 19:06:56 UTC
Fixed in 
policycoreutils-2.1.12-4.fc17

Comment 7 Fedora Update System 2012-10-24 13:04:58 UTC
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 23:56:53 UTC
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-11-01 01:25:38 UTC
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 23:29:36 UTC
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 15:56:02 UTC
We have fixed this in the F18 code base.

Comment 12 Scott Shambarger 2012-12-13 01:35:43 UTC
Any chance of getting this backported?  Most people probably won't discover the LANG workaround in F17...

Comment 13 Daniel Walsh 2012-12-17 20:27:53 UTC
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 07:05:03 UTC
Yep, tried the patch and both audit2allow and audit2why work as expected.

Comment 15 Daniel Walsh 2012-12-18 13:52:14 UTC
Fixed in policycoreutils-2.1.13-27.1.fc17

Comment 16 Fedora Update System 2012-12-18 13:54:03 UTC
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-19 01:16:50 UTC
Updated to 2.1.13-27.1 - audit2allow works great :)

Added karma on fedoraproject.

Comment 18 Fedora Update System 2012-12-20 16:09:24 UTC
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 13:23:05 UTC
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 19:29:06 UTC
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-06-01 02:27:17 UTC
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.