On Sun, Sep 18, 2016 at 07:13:27PM +0100, Ben Hutchings wrote: > On Sun, 2016-09-18 at 17:05 +0200, Jann Horn wrote: > > This ensures that self_privunit_id ("privilege unit ID") is only shared by > > processes that share the mm_struct and the signal_struct; not just > > spatially, but also temporally. In other words, if you do execve() or > > clone() without CLONE_THREAD, you get a new privunit_id that has never been > > used before. > [...] > > +void increment_privunit_counter(void) > > +{ > > + BUILD_BUG_ON(NR_CPUS > (1 << 16)); > > + current->self_privunit_id = this_cpu_add_return(exec_counter, NR_CPUS); > > +} > [...] > > This will wrap incorrectly if NR_CPUS is not a power of 2 (which is > unusual but allowed). If this wraps, hell breaks loose permission-wise - processes that have no relationship whatsoever with each other will suddenly be able to ptrace each other. The idea is that it never wraps. It wraps after (2^64)/NR_CPUS execs or forks on one CPU core. NR_CPUS is bounded to <=2^16, so in the worst case, it wraps after 2^48 execs or forks. On my system with 3.7GHz per core, 2^16 minimal sequential non-thread clone() calls need 1 second system time (and 2 seconds wall clock time, but let's disregard that), so 2^48 non-thread clone() calls should need over 100 years. But I guess both the kernel and machines get faster - if you think the margin might not be future-proof enough (or if you think I measured wrong and it's actually much faster), I guess I could bump this to a 128bit number.
Attachment:
signature.asc
Description: Digital signature