From: David Laight <David.Laight@ACULAB.COM>
To: 'Alexei Starovoitov' <alexei.starovoitov@gmail.com>,
Paul Moore <paul@paul-moore.com>
Cc: Martin KaFai Lau <martin.lau@kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Network Development <netdev@vger.kernel.org>,
LSM List <linux-security-module@vger.kernel.org>,
"selinux@vger.kernel.org" <selinux@vger.kernel.org>
Subject: RE: SO_PEERSEC protections in sk_getsockopt()?
Date: Mon, 10 Oct 2022 12:54:12 +0000 [thread overview]
Message-ID: <df4df4eb70594d65b40865ca00ecad09@AcuMS.aculab.com> (raw)
In-Reply-To: <CAADnVQJ5VgTNiEhEhOtESRrK0q3-pUSbZfAWL=tXv-s2GXqq8Q@mail.gmail.com>
From: Alexei Starovoitov
> Sent: 07 October 2022 22:55
....
> Not easy at all.
> There is only way place in the whole kernel that does:
> return sk_getsockopt(sk, SOL_SOCKET, optname,
> KERNEL_SOCKPTR(optval),
> KERNEL_SOCKPTR(optlen));
Until I add change my out of tree driver to work with
the new code.
(Although it actually needs to do a getsockopt into SCTP.)
I didn't spot the change to sk_getsockopt() going though.
But KERNEL_SOCKPTR() is really the wrong function/type
for the length.
It would be much safer to have a struct with two members,
one an __user pointer and one a kernel pointer both to
socklen_t.
It isn't really ideal for the buffer pointer either.
That started as a single field (assuming the caller
has verified the user/kernel status), then the is_kernel
field was added for architectures where user/kernel
addresses use the same values.
Then a horrid bug (forgotten where) forced the is_kernel
field be used everywhere.
Again a structure with two pointers would be much safer.
Indeed the length could likely be included as well.
That would even give scope for a short user buffer being
copied into kernel memory while letting code that needs
a long buffer (or ignores the length) still directly
access userspace.
I can't remember, but something makes me think that a lot
of the 'not checking the length' setsockopt calls were in
decnet - which has now been deleted.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2022-10-10 12:54 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-05 20:44 SO_PEERSEC protections in sk_getsockopt()? Paul Moore
2022-10-07 17:43 ` Paul Moore
2022-10-07 19:12 ` Alexei Starovoitov
2022-10-07 20:06 ` Paul Moore
2022-10-07 21:55 ` Alexei Starovoitov
2022-10-09 22:01 ` Paul Moore
2022-10-10 6:19 ` Alexei Starovoitov
2022-10-10 13:28 ` Paul Moore
2022-10-10 14:10 ` Alexei Starovoitov
2022-10-10 15:50 ` Paul Moore
2022-10-10 12:54 ` David Laight [this message]
2022-10-10 13:19 ` Paul Moore
2022-10-10 15:34 ` David Laight
2022-10-10 15:56 ` Paul Moore
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=df4df4eb70594d65b40865ca00ecad09@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=alexei.starovoitov@gmail.com \
--cc=ast@kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=martin.lau@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=selinux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox