From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ua0-f199.google.com (mail-ua0-f199.google.com [209.85.217.199]) by kanga.kvack.org (Postfix) with ESMTP id BB4946B0296 for ; Tue, 6 Feb 2018 13:36:04 -0500 (EST) Received: by mail-ua0-f199.google.com with SMTP id z11so1786185uaz.0 for ; Tue, 06 Feb 2018 10:36:04 -0800 (PST) Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id c94sor4962120uac.170.2018.02.06.10.36.03 for (Google Transport Security); Tue, 06 Feb 2018 10:36:03 -0800 (PST) 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 Message-ID: Subject: Re: [PATCH v2] socket: Provide put_cmsg_whitelist() for constant size copies Content-Type: text/plain; charset="UTF-8" Sender: owner-linux-mm@kvack.org List-ID: To: David Miller Cc: syzbot , LKML , Network Development , Eric Biggers , James Morse , keun-o.park@darkmatter.ae, Laura Abbott , Linux-MM , Ingo Molnar 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