On Thu, Mar 24, 2022 at 11:12:21AM -0700, Linus Torvalds wrote: > On Wed, Mar 23, 2022 at 1:24 PM Eric W. Biederman <ebiederm@xxxxxxxxxxxx> wrote: > > > > Please pull the per-namespace-ipc-sysctls-for-v5.18 tag from the git tree: > > Ugh. > > I pulled this. Then I stared at it for a long time. > > And then I decided that this is too ugly to live. > > I'm sorry. I think Alexey has probably spent a fair amount of time on > it, but I really think the sysctl code needs to be cleaned up way more > than this. Apparently it's my fault that the purpose of these changes is not clear. I did this refactoring not for the sake of refactoring as such. In my original patch [1], I was trying to fix the situation where the user cannot change the /proc/sys/fs/mqueue/* options inside rootless container. But then I split the changes into refactoring which fixes the hack and permission changes which I wanted to discuss and propose later. [1] https://lore.kernel.org/lkml/0f0408bb7fbf3187966a9bf19a98642a5d9669fe.1641225760.git.legion@xxxxxxxxxx/ > The old code was horribly hacky too, but that setup_ipc_sysctls() (and > setup_mq_sysctls()) thing that copies the whole sysctls table, and > then walks it entry by entry to modify it, is just too ugly for words. > > And then it hides things in .extra1, and because it does that it can't > use the normal "extra1 and extra2 contains the limits" so then at > write() time it copies it into a local one AGAIN only to set the > limits back so that it can call the normal routines again. > > Not ok. > > Yes, yes, the old code did some similar things - to set the 'data' > pointer. That was disgusting too. Don't get me wrong - the existing > code was nasty too. But this took nasty code, and doubled down on it. > > I really think this is a fundamental problem, and needs a more > fundamental fix than adding more and more of these kinds of nasty > hacks. > > And yes, that fundamental fix is almost certainly to pass in 'struct > cred *' to all those sysctl helper functions. > > Then, when you do the actual 'sysctl()' system calls, you pass in > 'current_cred()". > > And the /proc users would pass in file->f_cred. > > And yes, that patch might be quite messy, because we have quite a lot > of those random .proc_handler users. > > But *most* of them by far (at least in random code) use the standard > proc_dointvec_minmax() and friends, and won't even notice. > > And then the ones that are about namespace issues will have to > continue to do the nasty "make a copy and update the data pointer", > but *MAYBE* we could also introduce the notion of an "offset" to those > proc_dointvec_minmax() things to help them out (and at least avoid the > "make a copy" thing). > > Anyway, I really think we must not make that sysctl code even uglier > than it is today, and I think we need to move towards a model that > actually makes sense. And that "pass in the right cred" is the only > sensible model I can see. > > I haven't tried to create such a patch, and maybe Alexey already tried > to do something like that and it turned out to be too ugly for words > and that's why these nasty patches happened. > > But at least for now, I can't with a good conscience pull this. > > Sorry, > Linus OK. I'll try to come up with some other solution. -- Rgrds, legion