From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753242AbeBFSgN (ORCPT ); Tue, 6 Feb 2018 13:36:13 -0500 Received: from mail-ua0-f194.google.com ([209.85.217.194]:41525 "EHLO mail-ua0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753125AbeBFSgE (ORCPT ); Tue, 6 Feb 2018 13:36:04 -0500 X-Google-Smtp-Source: AH8x226FRipwg7lYNkH5lWu3J9Lc3wAgBv/XDJItpB9EucA451wkl9W+0mvn2Y96TURMyda54eVwRtGlA2gtLh5rLC8= MIME-Version: 1.0 In-Reply-To: <20180206.111949.1986970583522698316.davem@davemloft.net> References: <20180202102749.GA34019@beast> <20180205.100347.176614123780866781.davem@davemloft.net> <20180206.111949.1986970583522698316.davem@davemloft.net> From: Kees Cook Date: Wed, 7 Feb 2018 05:36:02 +1100 X-Google-Sender-Auth: t4P7c9rdpOctH2lPbIbj5EPGvr0 Message-ID: Subject: Re: [PATCH v2] socket: Provide put_cmsg_whitelist() for constant size copies To: David Miller Cc: syzbot , LKML , Network Development , Eric Biggers , James Morse , keun-o.park@darkmatter.ae, Laura Abbott , Linux-MM , Ingo Molnar Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 7, 2018 at 3:19 AM, David Miller wrote: > From: Kees Cook > Date: Tue, 6 Feb 2018 04:31:50 +1100 > >> On Tue, Feb 6, 2018 at 2:03 AM, David Miller wrote: >>> From: Kees Cook >>> 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). > > For some things like timestamps it can be important. Making put_cmsg() inline would help quite a bit with tracking the builtin_const-ness, and that could speed things up a little bit too. Would you be opposed to inlining? -Kees -- Kees Cook Pixel Security From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kees Cook Subject: Re: [PATCH v2] socket: Provide put_cmsg_whitelist() for constant size copies Date: Wed, 7 Feb 2018 05:36:02 +1100 Message-ID: References: <20180202102749.GA34019@beast> <20180205.100347.176614123780866781.davem@davemloft.net> <20180206.111949.1986970583522698316.davem@davemloft.net> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Cc: syzbot , LKML , Network Development , Eric Biggers , James Morse , keun-o.park@darkmatter.ae, Laura Abbott , Linux-MM , Ingo Molnar To: David Miller Return-path: In-Reply-To: <20180206.111949.1986970583522698316.davem@davemloft.net> Sender: owner-linux-mm@kvack.org List-Id: netdev.vger.kernel.org On Wed, Feb 7, 2018 at 3:19 AM, David Miller wrote: > From: Kees Cook > Date: Tue, 6 Feb 2018 04:31:50 +1100 > >> On Tue, Feb 6, 2018 at 2:03 AM, David Miller wrote: >>> From: Kees Cook >>> 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). > > For some things like timestamps it can be important. Making put_cmsg() inline would help quite a bit with tracking the builtin_const-ness, and that could speed things up a little bit too. Would you be opposed to inlining? -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: email@kvack.org