netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [WTF?] random test in netlink_sendmsg()
@ 2014-11-28  6:23 Al Viro
  2014-12-12 20:34 ` David Miller
  0 siblings, 1 reply; 12+ messages in thread
From: Al Viro @ 2014-11-28  6:23 UTC (permalink / raw)
  To: David Miller; +Cc: Patrick McHardy, netdev

	In netlink_sendmsg() we have the following:

        if (netlink_tx_is_mmaped(sk) &&
            msg->msg_iov->iov_base == NULL) {
                err = netlink_mmap_sendmsg(sk, msg, dst_portid, dst_group,
                                           siocb);
                goto out;
        }

Now, suppose sendmsg(2) is called with msg.msg_iovlen == 0.  We'll have
->msg_iov in kernel-side copy pointing at the uninitialized array in
stack frame of ___sys_sendmsg() - neither new nor old code touches elements
past the first msg_iovlen ones.  So in that case it checks if an
uninitialized word on stack is zero.

	What is that check trying to do?  Is that simply missing
"(msg->msg_iovlen > 0) &&"?  And why on the Earth didn't it simply use
zero msg_iovlen as the indicator, instead of messing with iovec contents?
Obviously too late to change, but... ouch.

Patrick, it had been that way since your commit last year ("netlink: implement
memory mapped sendmsg()"); could you explain what's the intended ABI?

Incidentally, WTF is "atomic_read(&nlk->mapped) > 1" part of check in
netlink_mmap_sendmsg() trying to achieve?  AFAICS, ->mapped tries to
keep track of the number of VMAs, right?  If so, it's bloody pointless -
one can have memory accessible in more than one process without any
extra VMAs.  Just clone(2) with CLONE_VM.  Voila - child shares the
entire address space.  No extra VMAs or calls of ->open() in sight...

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2014-12-14  4:39 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-28  6:23 [WTF?] random test in netlink_sendmsg() Al Viro
2014-12-12 20:34 ` David Miller
2014-12-12 21:32   ` Al Viro
2014-12-12 21:50     ` Florian Westphal
2014-12-12 22:14       ` Al Viro
2014-12-12 22:20         ` Florian Westphal
2014-12-13  1:07     ` David Miller
2014-12-13  1:54       ` Al Viro
2014-12-13  2:33         ` David Miller
2014-12-13  3:25           ` Al Viro
2014-12-13  4:51             ` Al Viro
2014-12-14  4:38               ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).