From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.5 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9825CC433E8 for ; Thu, 23 Jul 2020 15:41:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 79262206D8 for ; Thu, 23 Jul 2020 15:41:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726761AbgGWPlD (ORCPT ); Thu, 23 Jul 2020 11:41:03 -0400 Received: from a3.inai.de ([88.198.85.195]:44866 "EHLO a3.inai.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729551AbgGWPlC (ORCPT ); Thu, 23 Jul 2020 11:41:02 -0400 Received: by a3.inai.de (Postfix, from userid 25121) id 049975872C746; Thu, 23 Jul 2020 17:40:49 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by a3.inai.de (Postfix) with ESMTP id 038D360C4009F; Thu, 23 Jul 2020 17:40:49 +0200 (CEST) Date: Thu, 23 Jul 2020 17:40:49 +0200 (CEST) From: Jan Engelhardt To: Christoph Hellwig cc: "David S. Miller" , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Alexey Kuznetsov , Hideaki YOSHIFUJI , Eric Dumazet , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Netfilter Developer Mailing List , coreteam@netfilter.org, linux-sctp@vger.kernel.org, linux-hams@vger.kernel.org, linux-bluetooth@vger.kernel.org, bridge@lists.linux-foundation.org, linux-can@vger.kernel.org, dccp@vger.kernel.org, linux-decnet-user@lists.sourceforge.net, linux-wpan@vger.kernel.org, linux-s390@vger.kernel.org, mptcp@lists.01.org, lvs-devel@vger.kernel.org, rds-devel@oss.oracle.com, linux-afs@lists.infradead.org, tipc-discussion@lists.sourceforge.net, linux-x25@vger.kernel.org Subject: Re: [PATCH 04/26] net: add a new sockptr_t type In-Reply-To: <20200723060908.50081-5-hch@lst.de> Message-ID: References: <20200723060908.50081-1-hch@lst.de> <20200723060908.50081-5-hch@lst.de> User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Thursday 2020-07-23 08:08, Christoph Hellwig wrote: >+typedef struct { >+ union { >+ void *kernel; >+ void __user *user; >+ }; >+ bool is_kernel : 1; >+} sockptr_t; >+ >+static inline bool sockptr_is_null(sockptr_t sockptr) >+{ >+ return !sockptr.user && !sockptr.kernel; >+} """If the member used to access the contents of a union is not the same as the member last used to store a value, the object representation of the value that was stored is reinterpreted as an object representation of the new type (this is known as type punning). If the size of the new type is larger than the size of the last-written type, the contents of the excess bytes are unspecified (and may be a trap representation)""" As I am not too versed with the consequences of trap representations, I will just point out that a future revision of the C standard may introduce (proposal N2362) stronger C++-like requirements; as for union, that would imply a simple: """It's undefined behavior to read from the member of the union that wasn't most recently written.""" [cppreference.com] So, in the spirit of copy_from/to_sockptr, the is_null function should read { return sockptr.is_kernel ? !sockptr.user : !sockptr.kernel; } From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Engelhardt Subject: Re: [PATCH 04/26] net: add a new sockptr_t type Date: Thu, 23 Jul 2020 17:40:49 +0200 (CEST) Message-ID: References: <20200723060908.50081-1-hch@lst.de> <20200723060908.50081-5-hch@lst.de> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Return-path: In-Reply-To: <20200723060908.50081-5-hch@lst.de> Sender: netdev-owner@vger.kernel.org To: Christoph Hellwig Cc: "David S. Miller" , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Alexey Kuznetsov , Hideaki YOSHIFUJI , Eric Dumazet , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Netfilter Developer Mailing List , coreteam@netfilter.org, linux-sctp@vger.kernel.org, linux-hams@vger.kernel.org, linux-bluetooth@vger.kernel.org, bridge@lists.linux-foundation.org, linux-can@vger.kernel.org, dccp@vger.kernel.org, linux-decnet-user@lists.sourceforge.net, linux-wpan@vger.kernel.org, linux-s390@vger.kernel.org, mptcp@lists.01.org, lvs-de List-Id: linux-can.vger.kernel.org On Thursday 2020-07-23 08:08, Christoph Hellwig wrote: >+typedef struct { >+ union { >+ void *kernel; >+ void __user *user; >+ }; >+ bool is_kernel : 1; >+} sockptr_t; >+ >+static inline bool sockptr_is_null(sockptr_t sockptr) >+{ >+ return !sockptr.user && !sockptr.kernel; >+} """If the member used to access the contents of a union is not the same as the member last used to store a value, the object representation of the value that was stored is reinterpreted as an object representation of the new type (this is known as type punning). If the size of the new type is larger than the size of the last-written type, the contents of the excess bytes are unspecified (and may be a trap representation)""" As I am not too versed with the consequences of trap representations, I will just point out that a future revision of the C standard may introduce (proposal N2362) stronger C++-like requirements; as for union, that would imply a simple: """It's undefined behavior to read from the member of the union that wasn't most recently written.""" [cppreference.com] So, in the spirit of copy_from/to_sockptr, the is_null function should read { return sockptr.is_kernel ? !sockptr.user : !sockptr.kernel; } From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Thu, 23 Jul 2020 17:40:49 +0200 (CEST) From: Jan Engelhardt Subject: Re: [PATCH 04/26] net: add a new sockptr_t type In-Reply-To: <20200723060908.50081-5-hch@lst.de> Message-ID: References: <20200723060908.50081-1-hch@lst.de> <20200723060908.50081-5-hch@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: bpf-owner@vger.kernel.org List-ID: To: Christoph Hellwig Cc: "David S. Miller" , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Alexey Kuznetsov , Hideaki YOSHIFUJI , Eric Dumazet , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Netfilter Developer Mailing List , coreteam@netfilter.org, linux-sctp@vger.kernel.org, linux-hams@vger.kernel.org, linux-bluetooth@vger.kernel.org, bridge@lists.linux-foundation.org, linux-can@vger.kernel.org, dccp@vger.kernel.org, linux-decnet-user@lists.sourceforge.net, linux-wpan@vger.kernel.org, linux-s390@vger.kernel.org, mptcp@lists.01.org, lvs-devel@vger.kernel.org, rds-devel@oss.oracle.com, linux-afs@lists.infradead.org, tipc-discussion@lists.sourceforge.net, linux-x25@vger.kernel.org On Thursday 2020-07-23 08:08, Christoph Hellwig wrote: >+typedef struct { >+ union { >+ void *kernel; >+ void __user *user; >+ }; >+ bool is_kernel : 1; >+} sockptr_t; >+ >+static inline bool sockptr_is_null(sockptr_t sockptr) >+{ >+ return !sockptr.user && !sockptr.kernel; >+} """If the member used to access the contents of a union is not the same as the member last used to store a value, the object representation of the value that was stored is reinterpreted as an object representation of the new type (this is known as type punning). If the size of the new type is larger than the size of the last-written type, the contents of the excess bytes are unspecified (and may be a trap representation)""" As I am not too versed with the consequences of trap representations, I will just point out that a future revision of the C standard may introduce (proposal N2362) stronger C++-like requirements; as for union, that would imply a simple: """It's undefined behavior to read from the member of the union that wasn't most recently written.""" [cppreference.com] So, in the spirit of copy_from/to_sockptr, the is_null function should read { return sockptr.is_kernel ? !sockptr.user : !sockptr.kernel; } From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Engelhardt Date: Thu, 23 Jul 2020 15:40:49 +0000 Subject: Re: [PATCH 04/26] net: add a new sockptr_t type Message-Id: List-Id: References: <20200723060908.50081-1-hch@lst.de> <20200723060908.50081-5-hch@lst.de> In-Reply-To: <20200723060908.50081-5-hch@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Christoph Hellwig Cc: "David S. Miller" , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Alexey Kuznetsov , Hideaki YOSHIFUJI , Eric Dumazet , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Netfilter Developer Mailing List , coreteam@netfilter.org, linux-sctp@vger.kernel.org, linux-hams@vger.kernel.org, linux-bluetooth@vger.kernel.org, bridge@lists.linux-foundation.org, linux-can@vger.kernel.org, dccp@vger.kernel.org, linux-decnet-user@lists.sourceforge.net, linux-wpan@vger.kernel.org, linux-s390@vger.kernel.org, mptcp@lists.01.org, lvs-devel@vger.kernel.org, rds-devel@oss.oracle.com, linux-afs@lists.infradead.org, tipc-discussion@lists.sourceforge.net, linux-x25@vger.kernel.org On Thursday 2020-07-23 08:08, Christoph Hellwig wrote: >+typedef struct { >+ union { >+ void *kernel; >+ void __user *user; >+ }; >+ bool is_kernel : 1; >+} sockptr_t; >+ >+static inline bool sockptr_is_null(sockptr_t sockptr) >+{ >+ return !sockptr.user && !sockptr.kernel; >+} """If the member used to access the contents of a union is not the same as the member last used to store a value, the object representation of the value that was stored is reinterpreted as an object representation of the new type (this is known as type punning). If the size of the new type is larger than the size of the last-written type, the contents of the excess bytes are unspecified (and may be a trap representation)""" As I am not too versed with the consequences of trap representations, I will just point out that a future revision of the C standard may introduce (proposal N2362) stronger C++-like requirements; as for union, that would imply a simple: """It's undefined behavior to read from the member of the union that wasn't most recently written.""" [cppreference.com] So, in the spirit of copy_from/to_sockptr, the is_null function should read { return sockptr.is_kernel ? !sockptr.user : !sockptr.kernel; } From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Engelhardt Date: Thu, 23 Jul 2020 15:40:49 +0000 Subject: Re: [PATCH 04/26] net: add a new sockptr_t type Message-Id: List-Id: References: <20200723060908.50081-5-hch@lst.de> In-Reply-To: <20200723060908.50081-5-hch@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: dccp@vger.kernel.org On Thursday 2020-07-23 08:08, Christoph Hellwig wrote: >+typedef struct { >+ union { >+ void *kernel; >+ void __user *user; >+ }; >+ bool is_kernel : 1; >+} sockptr_t; >+ >+static inline bool sockptr_is_null(sockptr_t sockptr) >+{ >+ return !sockptr.user && !sockptr.kernel; >+} """If the member used to access the contents of a union is not the same as the member last used to store a value, the object representation of the value that was stored is reinterpreted as an object representation of the new type (this is known as type punning). If the size of the new type is larger than the size of the last-written type, the contents of the excess bytes are unspecified (and may be a trap representation)""" As I am not too versed with the consequences of trap representations, I will just point out that a future revision of the C standard may introduce (proposal N2362) stronger C++-like requirements; as for union, that would imply a simple: """It's undefined behavior to read from the member of the union that wasn't most recently written.""" [cppreference.com] So, in the spirit of copy_from/to_sockptr, the is_null function should read { return sockptr.is_kernel ? !sockptr.user : !sockptr.kernel; } From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Thu, 23 Jul 2020 17:40:49 +0200 (CEST) From: Jan Engelhardt In-Reply-To: <20200723060908.50081-5-hch@lst.de> Message-ID: References: <20200723060908.50081-1-hch@lst.de> <20200723060908.50081-5-hch@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Subject: Re: [Bridge] [PATCH 04/26] net: add a new sockptr_t type List-Id: Linux Ethernet Bridging List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Christoph Hellwig Cc: Alexei Starovoitov , linux-sctp@vger.kernel.org, linux-afs@lists.infradead.org, linux-s390@vger.kernel.org, rds-devel@oss.oracle.com, Daniel Borkmann , dccp@vger.kernel.org, bridge@lists.linux-foundation.org, lvs-devel@vger.kernel.org, coreteam@netfilter.org, mptcp@lists.01.org, Alexey Kuznetsov , linux-can@vger.kernel.org, Jakub Kicinski , linux-hams@vger.kernel.org, tipc-discussion@lists.sourceforge.net, linux-x25@vger.kernel.org, Eric Dumazet , Hideaki YOSHIFUJI , netdev@vger.kernel.org, linux-decnet-user@lists.sourceforge.net, linux-kernel@vger.kernel.org, linux-bluetooth@vger.kernel.org, Netfilter Developer Mailing List , linux-crypto@vger.kernel.org, bpf@vger.kernel.org, linux-wpan@vger.kernel.org, "David S. Miller" On Thursday 2020-07-23 08:08, Christoph Hellwig wrote: >+typedef struct { >+ union { >+ void *kernel; >+ void __user *user; >+ }; >+ bool is_kernel : 1; >+} sockptr_t; >+ >+static inline bool sockptr_is_null(sockptr_t sockptr) >+{ >+ return !sockptr.user && !sockptr.kernel; >+} """If the member used to access the contents of a union is not the same as the member last used to store a value, the object representation of the value that was stored is reinterpreted as an object representation of the new type (this is known as type punning). If the size of the new type is larger than the size of the last-written type, the contents of the excess bytes are unspecified (and may be a trap representation)""" As I am not too versed with the consequences of trap representations, I will just point out that a future revision of the C standard may introduce (proposal N2362) stronger C++-like requirements; as for union, that would imply a simple: """It's undefined behavior to read from the member of the union that wasn't most recently written.""" [cppreference.com] So, in the spirit of copy_from/to_sockptr, the is_null function should read { return sockptr.is_kernel ? !sockptr.user : !sockptr.kernel; }