Skip to contentSkip to conversation

Use nftw() instead of fts()

BUG libselinux Thomas Petazzoni 3 participants 3 messages Jul 1, 2016 – Jul 2, 2016 SELinux security module

lore
Share & tools
lore
#0 lore raw

Hello,

The recent versions of libselinux use the fts() function in src/selinux_restorecon.c. This function is BSD-only, and therefore not available in the musl C library, and only available optionally in the uClibc C library.

Would it be possible to use instead the POSIX-compliant nftw() function, which provides the same functionality?

In addition, using fts() is problematic, as on glibc versions <= 2.22, it is incompatible with large file support.

Thanks,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#1 lore raw
Quoted 7 lines · Thomas Petazzoni

Hello,

The recent versions of libselinux use the fts() function in src/selinux_restorecon.c. This function is BSD-only, and therefore not available in the musl C library, and only available optionally in the uClibc C library.

Quoted 5 lines

Would it be possible to use instead the POSIX-compliant nftw() function, which provides the same functionality?

In addition, using fts() is problematic, as on glibc versions <= 2.22, it is incompatible with large file support.

selinux userspace has been using fts() since 2009 (commit cce17290670ed7e1803ca6da660225ac01931d0c), when policycoreutils/setfiles was converted from nftw() to fts(). libselinux usage is newer, but src/selinux_restorecon.c is essentially a library function version of setfiles.

Not saying that it would be impossible to switch (back) to nftw(), but I guess we'd have to understand the cost/benefit tradeoff there. If fts() isn't available or well supported, why hasn't this previously been an issue for policycoreutils/setfiles?

#2 lore raw
Quoted 5 lines · Stephen Smalley
Quoted 4 lines · Thomas Petazzoni

The recent versions of libselinux use the fts() function in src/selinux_restorecon.c. This function is BSD-only, and therefore not available in the musl C library, and only available optionally in the uClibc C library.

[...]

Quoted 10 lines

selinux userspace has been using fts() since 2009 (commit cce17290670ed7e1803ca6da660225ac01931d0c), when policycoreutils/setfiles was converted from nftw() to fts(). libselinux usage is newer, but src/selinux_restorecon.c is essentially a library function version of setfiles.

Not saying that it would be impossible to switch (back) to nftw(), but I guess we'd have to understand the cost/benefit tradeoff there. If fts() isn't available or well supported, why hasn't this previously been an issue for policycoreutils/setfiles?

Do you know why the code was switched from nftw() to the fts-style functions? The commit message doesn't really say so, instead focusing on the compatibility and showing that there is no performance impact associated with it.

I think the main benefit here would be to allow musl- and ucLibc systems to use libselinux. I did a quick check to see if Android's libselinux port had to work around it as well, but apparently bionic uses the fts-style functions as well.

Wkr,
Sven Vermeulen