Re: [PATCH v2 7/11] Uprobes Implementation

From: Linus Torvalds
Date: Thu May 13 2010 - 18:28:51 EST




On Fri, 14 May 2010, Andi Kleen wrote:
>
> But isn't text usually shared? I don't see how you could set any
> break points or jump probes on text pages with that restriction.

Text is usually private, and read-only. Not generally MAP_SHARED. The
pages end up getting shared because nobody writes to them, but that's
almost accidental.

If you write to them, you get a nice clean COW fault, and you are
_supposed_ to get a nice clean COW fault. It's not changing any semantics:
the write is not visible to outside users, and those "get a private page"
semantics were what the mmap() was all about.

In contrast, if it's a MAP_SHARED mapping and writable, the write would
actually be _visible_ outside the process. And that's clearly totally
wrong on all levels. Tracing a process should _never_ cause visible damage
outside that process (you'd hope it wouldn't be all that visibel to the
tracee either, but that's still secondary).

The alternative, ie a MAP_SHARED but read-only mapping (which looks very
much like a private mapping) if you use get_user_pages(.force=1), the
kernel will actually end up forcing a COW break, because making the write
visible outside would be a security issue (you don't even have the right
to write to the thing).

Notice how the MAP_SHARED case - writable or not - ends up doing the wrong
thing. Arguably it does the _even_worse_ thing in the writable case, but
in either case it's not good.

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/