All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: David Miller <davem@davemloft.net>
Cc: syzbot <syzbot+e2d6cfb305e9f3911dea@syzkaller.appspotmail.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Network Development <netdev@vger.kernel.org>,
	Eric Biggers <ebiggers3@gmail.com>,
	James Morse <james.morse@arm.com>,
	keun-o.park@darkmatter.ae, Laura Abbott <labbott@redhat.com>,
	Linux-MM <linux-mm@kvack.org>, Ingo Molnar <mingo@kernel.org>
Subject: Re: [PATCH v2] socket: Provide put_cmsg_whitelist() for constant size copies
Date: Tue, 6 Feb 2018 04:31:50 +1100	[thread overview]
Message-ID: <CAGXu5j+VnhgXFajjxR7HJkN=Z6r3Kfw-+Gg2x37AacOD6C+Wdg@mail.gmail.com> (raw)
In-Reply-To: <20180205.100347.176614123780866781.davem@davemloft.net>

On Tue, Feb 6, 2018 at 2:03 AM, David Miller <davem@davemloft.net> wrote:
> From: Kees Cook <keescook@chromium.org>
> Date: Fri, 2 Feb 2018 02:27:49 -0800
>
>> @@ -343,6 +343,14 @@ struct ucred {
>>
>>  extern int move_addr_to_kernel(void __user *uaddr, int ulen, struct sockaddr_storage *kaddr);
>>  extern int put_cmsg(struct msghdr*, int level, int type, int len, void *data);
>> +/*
>> + * Provide a bounce buffer for copying cmsg data to userspace when the
>> + * target memory isn't already whitelisted for hardened usercopy.
>> + */
>> +#define put_cmsg_whitelist(_msg, _level, _type, _ptr) ({             \
>> +             typeof(*(_ptr)) _val = *(_ptr);                         \
>> +             put_cmsg(_msg, _level, _type, sizeof(_val), &_val);     \
>> +     })
>
> I understand what you are trying to achieve, but it's at a real cost
> here.  Some of these objects are structures, for example the struct
> sock_extended_err is 16 bytes.

It didn't look like put_cmsg() was on a fast path, so it seemed like a
bounce buffer was the best solution here (and it's not without
precedent).

> And now we're going to copy it twice, once into the on-stack copy,
> and then once again into the CMSG blob.
>
> Please find a way to make hardened user copy happy without adding
> new overhead.

Another idea would be breaking put_cmsg() up into a macro with helper
functions, rearrange the arguments to avoid the math, and leaving the
copy_to_user() inline to see the const-ness, but that seemed way
uglier to me.

I'll think about it some more, but I think having put_cmsg_whitelist()
called only in a few places is reasonable here.

-Kees

-- 
Kees Cook
Pixel Security

WARNING: multiple messages have this Message-ID (diff)
From: Kees Cook <keescook@chromium.org>
To: David Miller <davem@davemloft.net>
Cc: syzbot <syzbot+e2d6cfb305e9f3911dea@syzkaller.appspotmail.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Network Development <netdev@vger.kernel.org>,
	Eric Biggers <ebiggers3@gmail.com>,
	James Morse <james.morse@arm.com>,
	keun-o.park@darkmatter.ae, Laura Abbott <labbott@redhat.com>,
	Linux-MM <linux-mm@kvack.org>, Ingo Molnar <mingo@kernel.org>
Subject: Re: [PATCH v2] socket: Provide put_cmsg_whitelist() for constant size copies
Date: Tue, 6 Feb 2018 04:31:50 +1100	[thread overview]
Message-ID: <CAGXu5j+VnhgXFajjxR7HJkN=Z6r3Kfw-+Gg2x37AacOD6C+Wdg@mail.gmail.com> (raw)
In-Reply-To: <20180205.100347.176614123780866781.davem@davemloft.net>

On Tue, Feb 6, 2018 at 2:03 AM, David Miller <davem@davemloft.net> wrote:
> From: Kees Cook <keescook@chromium.org>
> Date: Fri, 2 Feb 2018 02:27:49 -0800
>
>> @@ -343,6 +343,14 @@ struct ucred {
>>
>>  extern int move_addr_to_kernel(void __user *uaddr, int ulen, struct sockaddr_storage *kaddr);
>>  extern int put_cmsg(struct msghdr*, int level, int type, int len, void *data);
>> +/*
>> + * Provide a bounce buffer for copying cmsg data to userspace when the
>> + * target memory isn't already whitelisted for hardened usercopy.
>> + */
>> +#define put_cmsg_whitelist(_msg, _level, _type, _ptr) ({             \
>> +             typeof(*(_ptr)) _val = *(_ptr);                         \
>> +             put_cmsg(_msg, _level, _type, sizeof(_val), &_val);     \
>> +     })
>
> I understand what you are trying to achieve, but it's at a real cost
> here.  Some of these objects are structures, for example the struct
> sock_extended_err is 16 bytes.

It didn't look like put_cmsg() was on a fast path, so it seemed like a
bounce buffer was the best solution here (and it's not without
precedent).

> And now we're going to copy it twice, once into the on-stack copy,
> and then once again into the CMSG blob.
>
> Please find a way to make hardened user copy happy without adding
> new overhead.

Another idea would be breaking put_cmsg() up into a macro with helper
functions, rearrange the arguments to avoid the math, and leaving the
copy_to_user() inline to see the const-ness, but that seemed way
uglier to me.

I'll think about it some more, but I think having put_cmsg_whitelist()
called only in a few places is reasonable here.

-Kees

-- 
Kees Cook
Pixel Security

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2018-02-05 17:32 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-02 10:27 [PATCH v2] socket: Provide put_cmsg_whitelist() for constant size copies Kees Cook
2018-02-02 10:27 ` Kees Cook
2018-02-05 15:03 ` David Miller
2018-02-05 15:03   ` David Miller
2018-02-05 17:31   ` Kees Cook [this message]
2018-02-05 17:31     ` Kees Cook
2018-02-06 16:19     ` David Miller
2018-02-06 16:19       ` David Miller
2018-02-06 18:36       ` Kees Cook
2018-02-06 18:36         ` Kees Cook
2018-02-06 18:42         ` David Miller
2018-02-06 18:42           ` David Miller

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='CAGXu5j+VnhgXFajjxR7HJkN=Z6r3Kfw-+Gg2x37AacOD6C+Wdg@mail.gmail.com' \
    --to=keescook@chromium.org \
    --cc=davem@davemloft.net \
    --cc=ebiggers3@gmail.com \
    --cc=james.morse@arm.com \
    --cc=keun-o.park@darkmatter.ae \
    --cc=labbott@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mingo@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=syzbot+e2d6cfb305e9f3911dea@syzkaller.appspotmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.