[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHk-=whzaCCucr9odvFWcWr72nraRgejD90Nwb2tP8SBE2LTQw@mail.gmail.com>
Date: Sat, 16 Dec 2023 10:26:04 -0800
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: Amir Goldstein <amir73il@...il.com>
Cc: Vinicius Costa Gomes <vinicius.gomes@...el.com>, hu1.chen@...el.com, miklos@...redi.hu,
malini.bhandaru@...el.com, tim.c.chen@...el.com, mikko.ylinen@...el.com,
lizhen.you@...el.com, linux-unionfs@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-fsdevel <linux-fsdevel@...r.kernel.org>,
Christian Brauner <brauner@...nel.org>, David Howells <dhowells@...hat.com>
Subject: Re: [RFC] HACK: overlayfs: Optimize overlay/restore creds
On Sat, 16 Dec 2023 at 02:16, Amir Goldstein <amir73il@...il.com> wrote:
>
> As a matter of fact, maybe it makes sense to embed a non-refcounted
> copy in the struct used for the guard:
No, please don't. A couple of reasons:
- that 'struct cred' is not an insignificant size, so stack usage is noticeable
- we really should strive to avoid passing pointers to random stack
elements around
Don't get me wrong - we pass structures around on the stack all the
time, but it _has_ been a problem with stack usage. Those things tend
to grow..
So in general, the primary use of "pointers to stack objects" is for
when it's either trivially tiny, or when it's a struct that is
explicitly designed for that purpose as a kind of an "extended set of
arguments" (think things like the "tlb_state" for the TLB flushing, or
the various iterator structures we use etc).
When we have a real mainline kernel struct like 'struct cred' that
commonly gets passed around as a pointer argument that *isn't* on the
stack, I get nervous when people then pass it around on the stack too.
It's just too easy to mistakenly pass it off with the wrong lifetime,
and stack corruption is *so* nasty to debug that it's just horrendous.
Yes, lifetime problems are nasty to debug even when it's not some
mis-use of a stack object, but at least for slab allocations etc we
have various generic debug tools that help find them.
For the "you accessed things under the stack, possibly from the wrong
thread", I don't think any of our normal debug coverage will help at
all.
So yes, stack allocations are efficient and fast, and we do use them,
but please don't use them for something like 'struct cred' that has a
proper allocator function normally.
I just removed the CONFIG_DEBUG_CREDENTIALS code, because the fix for
a potential overflow made it have bad padding, and rather than fix the
padding I thought it was better to just remove the long-unused debug
code that just made that thing even more unwieldly than it is.
But I thought that largely because our 'struct cred' use has been
quite stable for a long time (and the original impetus for all that
debug code was the long-ago switch to using the copy-on-write
behavior).
Let's not break that stability with suddenly having a "sometimes it's
allocated on the stack" model.
Linus
Powered by blists - more mailing lists