Bug 50401
Summary: | [PATCH]Use of iterate_fd() in security/selinux/hooks.c causes user visible effects | ||
---|---|---|---|
Product: | Other | Reporter: | Pavel Roskin (plroskin) |
Component: | Loadable Security Modules (LSM) | Assignee: | Other/LSM (other_lsm) |
Status: | RESOLVED CODE_FIX | ||
Severity: | normal | CC: | akpm, alan, andrafast13 |
Priority: | P1 | ||
Hardware: | All | ||
OS: | Linux | ||
Kernel Version: | 3.7-rc5 | Subsystem: | |
Regression: | Yes | Bisected commit-id: | |
Attachments: |
Fix for match_file(), successfully tested
watch |
Description
Pavel Roskin
2012-11-12 03:35:02 UTC
Created attachment 86131 [details]
Fix for match_file(), successfully tested
I've checked other uses of iterate_fd(). drivers/tty/tty_io.c appears to have the same problem. The match function this_tty() gets an incremented file descriptor and increments it again. Fortunately, the result of iterate_fd() is only used in printk(). arch/powerpc/platforms/cell/spufs/coredump.c may have a real problem, as the the result of iterate_fd() is returned. We have the same pattern there - two increments and one decrement by 1. Callers of coredump_next_context() increment fd on their own, so it's possible that fd skips every other file descriptor. net/core/netprio_cgroup.c does some fishy things with casts. But the match function update_netprio() always returns 0 and ignores the fd argument (called "n" there), so it should not be affected. It's disappointing that a new exported function (interate_fd) is introduced with no documentation. Also, the choice of 0 as the special value is a poor choice for a function working with file descriptors. -ENOENT would be the the Linux way. -1 might be OK (the UNIX userspace way). But 0 is insane IMHO. That's what causes this mess with increments. I'm afraid I'll not have time to implement a complete rewrite for iterate_fd() any time soon. I have no hardware to test some cases and I would have to be extremely careful with that code. I hoped Al Viro would participate, but I cannot even add him to CC (please help if you can). I think the best approach for Linux 3.7 would be to revert the patch that introduced iterate_fd(). That would restore the tested code. Further patches to introduce iterate_fd() should be tested and reviewed properly. Viro doesn't do bugzilla so you won't be able to add him I'd suggest you email Linus including the test case and ask him to pull it and Cc viro on the email. Created attachment 219101 [details]
watch
Fixed in commit 45525b26a46cd593cb72070304c4cd7c8391bd37 (v3.7-rc1-6-g45525b26a46c), closing. |