Re: [PATCH][RFC] %pd - for printing dentry name

From: Linus Torvalds
Date: Mon Feb 01 2010 - 23:22:32 EST




On Mon, 1 Feb 2010, Al Viro wrote:
>
> Ehh... RCU will save you from stepping on freed memory, but it still will
> leave the joy of half-updated string with length out of sync with it, etc.

Sure. But do we care?

Every printk _should_ be on a dentry that we have a reference to, anyway.
Otherwise, how did we find it?

So yeah, then there is the race with rename(), but (a) it's not going to
happen, (b) if we race with rename there is no "one" correct solution
anyway, so (c) what we really want to protect against is the printk
causing problems (like an oops from DEBUG_PAGEALLOC and freeing the old
name).

> We probably can get away with that, but we'll have to be a lot more careful
> with the order of updating these suckers in d_move_locked et.al.

I wouldn't worry about it too much. So what if we get a screwed up name?
If we use "%.*s" to print the name, we know that we won't overstep the old
name even if the NUL termination somehow went away (because we're busy
copying a new, longer, name over it or whatever).

So I would not worry too much about sometimes showing a nonsensical name
that may be the result of a concurrent rename. I'd only worry about it not
oopsing or stepping on memory that hasn't had _either_ the old or the new
name in it.

That's why I think an RCU solution should be sufficient..

Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/