Skip to contentSkip to conversation

awk, isatty(), libc and ioctl()

DISCUSSION Erich Schubert 3 participants 6 messages Sep 13, 2006 – Sep 18, 2006 SELinux security module

lore
Share & tools
lore
#0 lore raw

Hi,
one of the few audit errors remaining on my test box is
initrc_t postfix_etc_t:file ioctl;

Which sounds like an odd behaviour to me. I've tracked it down to the init script using an awk-one-liner to determine if it needs to sync the chroot.
Awk however calls isatty() on any file it processes. Which is implemented in the libc apparently using an ioctl TCGETS; this will fail for regular files.

So should I add a "dontaudit" for this behaviour (but it will resurface again whenever awk is used in a script!) or maybe find a workaround for isatty()?
Awk (or isatty()) could probably use fstat(), too. Anyone deep enough in kernel interfaces to comment on that? Any chance of modifying the LSM hooks to not audit this type of behaviour (calling unsupported ioctls)? Or anything?

best regards,
Erich Schubert

Signature · 11 lines
    erich@(vitavonni.de|debian.org)    --    GPG Key ID: 4B3A135C   (o_
      The future is here. It's just not evenly distributed yet.     //\
   Es ist beschämender seinen Freunden zu mißtrauen als von ihnen   V_/_
        getäuscht zu werden. --- François de la Rochefoucauld



--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#1 lore raw
Quoted 9 lines · Erich Schubert

one of the few audit errors remaining on my test box is
initrc_t postfix_etc_t:file ioctl;

Which sounds like an odd behaviour to me. I've tracked it down to the init script using an awk-one-liner to determine if it needs to sync the chroot.
Awk however calls isatty() on any file it processes. Which is implemented in the libc apparently using an ioctl TCGETS; this will fail for regular files.

One thing to note is that Perl has the same issue in regard to ioctl() on all files.

The isatty() code could stat the file first, anything that's not a character device is not a tty. But I doubt that we are going to get a change to glibc for this.

It's easiest to just allow or dontaudit the ioctl. It's what we've been doing for the past 5 years...

Signature · 9 lines
[email protected]
http://etbe.blogspot.com/          My Blog

http://www.coker.com.au/sponsorship.html Sponsoring Free Software development

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#2 lore raw

Hello Russel,

Quoted 2 lines

One thing to note is that Perl has the same issue in regard to ioctl() on all files.

What can ioctl() on *regular* files do? The "ioctl" manpage just mentions "special files".

I mean... we'll probably have to add ioctl dontaudits for so many domains, we might want to go with something like
"dontaudit domain file_type:file ioctl;"
at least for any user domain (I mean, most admins will allow their users to use awk or perl in one way or another).

best regards,
Erich Schubert

Signature · 12 lines
   erich@(vitavonni.de|debian.org)    --    GPG Key ID: 4B3A135C    (o_
     You know we all became mathematicians for the same reason:     //\
                  we were lazy. --- Max Rosenlicht                  V_/_
       Wenn Leute nicht glauben, dass Mathematik einfach ist,
            dann nur deshalb, weil sie nicht begreifen,
        wie kompliziert das Leben ist. --- John von Neumann


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#3 lore raw
Quoted 6 lines · Erich Schubert

Hello Russel,

Quoted 2 lines

One thing to note is that Perl has the same issue in regard to ioctl() on all files.

What can ioctl() on *regular* files do? The "ioctl" manpage just mentions "special files".

For all files, you have FIBMAP, FIGETBZ, FIONREAD.
Then the individual filesystem types implement their own operations, like ext3 has [gs]etflags, [gs]etversion, etc.

There has been past discussion of altering the SELinux ioctl checking, including some rfc/patches [1], but the main problem is someone taking the time to not only implement such a patch but also to thoroughly test its effect on applications, update current policy, provide a graceful way to migrate from the old checks to the new [2], etc.

[1] http://marc.theaimsgroup.com/?l=selinux&m=113519095102526&w=2
[2] https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=195238

Quoted 5 lines

I mean... we'll probably have to add ioctl dontaudits for so many domains, we might want to go with something like
"dontaudit domain file_type:file ioctl;"
at least for any user domain (I mean, most admins will allow their users to use awk or perl in one way or another).

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#4 lore raw

Hello Stephen,
So what should we do - add the missing dontaudit/allow rules, provide patches for awk/perl (and likely others) to not use isatty() on regular files but stat() first, or ask the glibc maintainers to modify isatty()?

best regards,
Erich Schubert

Signature · 10 lines
    erich@(vitavonni.de|debian.org)    --    GPG Key ID: 4B3A135C    (o_
     Which is worse: ignorance or apathy? Who knows? Who cares?      //\
  Wer keine Zeit mehr mit echten Freunden verbringt, der wird bald   V_/_
          sein Gleichgewicht verlieren. --- Michael Levine


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#5 lore raw
Quoted 4 lines · Erich Schubert

Hello Stephen,
So what should we do - add the missing dontaudit/allow rules, provide patches for awk/perl (and likely others) to not use isatty() on regular files but stat() first, or ask the glibc maintainers to modify isatty()?

I'm doubtful that the latter two options are viable. More likely:
1) Add dontaudit rules as needed for now,
2) Reconsider the SELinux ioctl checking in the future.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.