Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4975624pxv; Tue, 27 Jul 2021 23:20:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwi7eBDss58Pb5qiT9j4M2bdAmyO1p2vaQlnybvweSPbbSid0XdK5cAZky8jUDAwhrY/6eA X-Received: by 2002:a17:906:b750:: with SMTP id fx16mr19049910ejb.108.1627453220148; Tue, 27 Jul 2021 23:20:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627453220; cv=none; d=google.com; s=arc-20160816; b=k8HoCxeS16k+NKFikDpjAG2hu56P0sN+ERUwbjl5o6C788NdJqQrzZUuAhObeVPv7B dkPFFbKuumwi2+prmCtefvAqJWxoTtzUlP7Hn6u3GjgCsBXYPkFbZNCp8M1tCRPUKkyd 6TgyqksjcDxaC0MMGmhgTzkGTC5ZyqOw1rOREgagwoNIS/rD0BvxCZPeMIKzRzIxTrDV At5XPhggyQvbNmmhfQmNwl4DT2zC3TaZLuwdfkdDBkFR+NSMZ1+2zVxWjlbVJSttYNDF k6UyGEAJIgqcJMnJP3vWI4X2auKBBicTDqeIMSu8djBd50bV1x1A+LZFZGSJFlSg8yG8 sy5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=bsu7xGENC4+aEoRNs30EBk+MtK8ofLqZ2O8fS1l7w30=; b=Kg7P7lxXcqb3wP97PggWI8xieFDLcljr7xFkeg4PKH9vWvVdjZR4z/1VecHj0qdDDi f8iyPJ5E6ESSElpDvXYp8JleNk13ucybCeF9eSjKQ6zrwiyxZwah+ZxI45c8h4dKy2ih qOybU2XfdR58PYENvoXh9ExPP37mxiwgCBRV3GS2MuVLGpWsjs+8FN5ERRMr3g4Xxx7x HVJgXsww8J1eK8bO82+vu5kkVHn0baiSvpqdq6Bi66Aiy59iVRzLIMm2nBFFHt0qWwnk fjswt7xriDeHKzVBK/rk+OMcgMbbyGRUshU1/SnGpoikUp1XyJ0gND2EL58MVvcecsF0 scLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=G415GDub; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h16si5021321eds.56.2021.07.27.23.19.54; Tue, 27 Jul 2021 23:20:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=G415GDub; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233848AbhG1GTp (ORCPT + 99 others); Wed, 28 Jul 2021 02:19:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:57494 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231199AbhG1GTo (ORCPT ); Wed, 28 Jul 2021 02:19:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2B8BC60F59; Wed, 28 Jul 2021 06:19:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627453182; bh=jzQuz+FxNSuPOpcBxvBdUPKEHHxSVIBlwZ520J114Qg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=G415GDubuNnoFZNUO3Akbs6Yro6HwxHPDYBUPD1Je/Dkmdt9ysqOtqcLKUEN6Xj0e Qxw0gJNQdccgSCI3xkXBWKMvEGgUGYJw/tQMw3OCUE1b0g7y22+6L2lFw7ih+DbI7Q UbltwqAC2OGz4xic/gOwmBxTzDbXvlRGpGObqXu8= Date: Wed, 28 Jul 2021 08:19:40 +0200 From: Greg Kroah-Hartman To: "Gustavo A. R. Silva" Cc: Kees Cook , linux-hardening@vger.kernel.org, "Gustavo A. R. Silva" , Keith Packard , Andrew Morton , linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-staging@lists.linux.dev, linux-block@vger.kernel.org, linux-kbuild@vger.kernel.org, clang-built-linux@googlegroups.com Subject: Re: [PATCH 19/64] ip: Use struct_group() for memcpy() regions Message-ID: References: <20210727205855.411487-1-keescook@chromium.org> <20210727205855.411487-20-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org On Wed, Jul 28, 2021 at 01:14:33AM -0500, Gustavo A. R. Silva wrote: > > > On 7/28/21 00:55, Greg Kroah-Hartman wrote: > > On Tue, Jul 27, 2021 at 01:58:10PM -0700, Kees Cook wrote: > >> In preparation for FORTIFY_SOURCE performing compile-time and run-time > >> field bounds checking for memcpy(), memmove(), and memset(), avoid > >> intentionally writing across neighboring fields. > >> > >> Use struct_group() in struct flowi4, struct ipv4hdr, and struct ipv6hdr > >> around members saddr and daddr, so they can be referenced together. This > >> will allow memcpy() and sizeof() to more easily reason about sizes, > >> improve readability, and avoid future warnings about writing beyond the > >> end of saddr. > >> > >> "pahole" shows no size nor member offset changes to struct flowi4. > >> "objdump -d" shows no meaningful object code changes (i.e. only source > >> line number induced differences.) > >> > >> Note that since this is a UAPI header, struct_group() has been open > >> coded. > >> > >> Signed-off-by: Kees Cook > >> --- > >> include/net/flow.h | 6 ++++-- > >> include/uapi/linux/if_ether.h | 12 ++++++++++-- > >> include/uapi/linux/ip.h | 12 ++++++++++-- > >> include/uapi/linux/ipv6.h | 12 ++++++++++-- > >> net/core/flow_dissector.c | 10 ++++++---- > >> net/ipv4/ip_output.c | 6 ++---- > >> 6 files changed, 42 insertions(+), 16 deletions(-) > >> > >> diff --git a/include/net/flow.h b/include/net/flow.h > >> index 6f5e70240071..f1a3b6c8eae2 100644 > >> --- a/include/net/flow.h > >> +++ b/include/net/flow.h > >> @@ -81,8 +81,10 @@ struct flowi4 { > >> #define flowi4_multipath_hash __fl_common.flowic_multipath_hash > >> > >> /* (saddr,daddr) must be grouped, same order as in IP header */ > >> - __be32 saddr; > >> - __be32 daddr; > >> + struct_group(addrs, > >> + __be32 saddr; > >> + __be32 daddr; > >> + ); > >> > >> union flowi_uli uli; > >> #define fl4_sport uli.ports.sport > >> diff --git a/include/uapi/linux/if_ether.h b/include/uapi/linux/if_ether.h > >> index a0b637911d3c..8f5667b2ea92 100644 > >> --- a/include/uapi/linux/if_ether.h > >> +++ b/include/uapi/linux/if_ether.h > >> @@ -163,8 +163,16 @@ > >> > >> #if __UAPI_DEF_ETHHDR > >> struct ethhdr { > >> - unsigned char h_dest[ETH_ALEN]; /* destination eth addr */ > >> - unsigned char h_source[ETH_ALEN]; /* source ether addr */ > >> + union { > >> + struct { > >> + unsigned char h_dest[ETH_ALEN]; /* destination eth addr */ > >> + unsigned char h_source[ETH_ALEN]; /* source ether addr */ > >> + }; > >> + struct { > >> + unsigned char h_dest[ETH_ALEN]; /* destination eth addr */ > >> + unsigned char h_source[ETH_ALEN]; /* source ether addr */ > >> + } addrs; > > > > A union of the same fields in the same structure in the same way? > > > > Ah, because struct_group() can not be used here? Still feels odd to see > > in a userspace-visible header. > > > >> + }; > >> __be16 h_proto; /* packet type ID field */ > >> } __attribute__((packed)); > >> #endif > >> diff --git a/include/uapi/linux/ip.h b/include/uapi/linux/ip.h > >> index e42d13b55cf3..33647a37e56b 100644 > >> --- a/include/uapi/linux/ip.h > >> +++ b/include/uapi/linux/ip.h > >> @@ -100,8 +100,16 @@ struct iphdr { > >> __u8 ttl; > >> __u8 protocol; > >> __sum16 check; > >> - __be32 saddr; > >> - __be32 daddr; > >> + union { > >> + struct { > >> + __be32 saddr; > >> + __be32 daddr; > >> + } addrs; > >> + struct { > >> + __be32 saddr; > >> + __be32 daddr; > >> + }; > > > > Same here (except you named the first struct addrs, not the second, > > unlike above). > > > > > >> + }; > >> /*The options start here. */ > >> }; > >> > >> diff --git a/include/uapi/linux/ipv6.h b/include/uapi/linux/ipv6.h > >> index b243a53fa985..1c26d32e733b 100644 > >> --- a/include/uapi/linux/ipv6.h > >> +++ b/include/uapi/linux/ipv6.h > >> @@ -130,8 +130,16 @@ struct ipv6hdr { > >> __u8 nexthdr; > >> __u8 hop_limit; > >> > >> - struct in6_addr saddr; > >> - struct in6_addr daddr; > >> + union { > >> + struct { > >> + struct in6_addr saddr; > >> + struct in6_addr daddr; > >> + } addrs; > >> + struct { > >> + struct in6_addr saddr; > >> + struct in6_addr daddr; > >> + }; > > > > addrs first? Consistancy is key :) > > I think addrs should be second. In general, I think all newly added > non-anonymous structures should be second. Why not use a local version of the macro like was done in the DRM header file, to make it always work the same and more obvious what is happening? If I were a userspace developer and saw the above, I would think that the kernel developers have lost it :) thanks, greg k-h