Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp778058rwd; Thu, 8 Jun 2023 07:38:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5RnO1g3cE4fyIulMwecwcTcAZe+X6+luZVBF4sexLxYnxGZ3dLMZ64i1U5PhKjFhl4bydM X-Received: by 2002:a92:d089:0:b0:325:b002:89b4 with SMTP id h9-20020a92d089000000b00325b00289b4mr8787848ilh.25.1686235121546; Thu, 08 Jun 2023 07:38:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686235121; cv=none; d=google.com; s=arc-20160816; b=VI5VJ2lyPXradsa3iXRwqEp+yRXb8BR5uu7uuO9C0Anq0vqfB04ZKAQU/I0jhWueaA K/BIjr7RKcrh+cAcccxPfDHLYk/fsTmu72pXEwx7jIUjC7wC16pBmh2Dq3e+5PBdcGNn WrCEAEEBu6SOhzbKWrg4XjPCs8gDhK7tqZ2mlS1ao4dAWUJL9s7auJgxL1cbaflhEjvF V0vt6J8EbrMvYdtt7da5aelnV9zs2adt/9qw6vXDdQwMa9/KZ/dmjdk6WN+MJNWk1nal NLW9rI2jY7oSZP2ZAWyZ2DTdwWGg5K4nHCplgntwKEnpwb0BbwV3gPmyygqQba2STFAW IhnA== 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; bh=40BlcYIOiCiG2tmKHXdb8ewCMjsbNxSjJq3O+2btqpQ=; b=J5nTsTlDQOqqAvf6BLPBBQT7nZroYv/ECBjPol+ffZd4TQ31qCN7ZLOOjo/5lue2wG cum57WOmjzdOpZUFIp4UBghd3ZSN6wIucRFiaW7BO+BB2lU1nv7F9ReM/s/qnVMQA9uE rp29Jfktu2Zop3UJvUwZLOx+oiJPNFKbMlcAp0JAKkJ3t4HfTS58URYppoqYUrFhFNOJ QaeAPmCShTiZQwXzmWK/raQccOIp6YdWErMiNtTNRuGs8LGf+/XL3vRUgJ/TdPT/6XSn AfSV4WVqkSscTzJEZsB6kIzjBiZdXr2/y40QZtCxEwuekWuFHaiA/yX3GXaW031m+M9e MDUg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q39-20020a17090a1b2a00b0025669d0176asi2786297pjq.134.2023.06.08.07.38.29; Thu, 08 Jun 2023 07:38:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237006AbjFHOf6 (ORCPT + 99 others); Thu, 8 Jun 2023 10:35:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235991AbjFHOf5 (ORCPT ); Thu, 8 Jun 2023 10:35:57 -0400 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF1872D58; Thu, 8 Jun 2023 07:35:52 -0700 (PDT) Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-3f732d37d7cso6156945e9.2; Thu, 08 Jun 2023 07:35:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686234951; x=1688826951; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=40BlcYIOiCiG2tmKHXdb8ewCMjsbNxSjJq3O+2btqpQ=; b=LVrKO6oUKvcg8/2nyEi5q5+WzyFpfXLtC9snIpVkUhAF/im6GPJ9K1UHCkpj3grB7i Tga1U0dBib2zApXx2OAuv4qnBbIRYP+Zp+pQz7juSH74Bqv2ggKKvImI9gi1dyKxO+a0 WZ8K8GJyV2pElh6tPS0H7FvPJNgRTmk36qRWGy07BY6JbkvMtBhsjLiRHNortriPPEiK tVV4VYD3ELDTAvCL8LgkQsqudKFsOlczE1r9jY07Pu2PwvTyX2pMxNKpDV/72LDtsVJD 9DUmRM0itaOUoPRDPLce+z26UaJx5r7RtLoiwHt1ZspbI/fw7SIZ3zSHB0f+CLjMDF+y Hmqg== X-Gm-Message-State: AC+VfDzFYv4Os6ikUPuim7meOkSrFWoM2rHKy33n8MVaIGSVIiDuocVf SZ2E+4ruHgz0f6tcVjzENdY= X-Received: by 2002:a05:600c:21cf:b0:3f6:143:7c4b with SMTP id x15-20020a05600c21cf00b003f601437c4bmr1728617wmj.6.1686234951071; Thu, 08 Jun 2023 07:35:51 -0700 (PDT) Received: from gmail.com (fwdproxy-cln-027.fbsv.net. [2a03:2880:31ff:1b::face:b00c]) by smtp.gmail.com with ESMTPSA id s5-20020a7bc385000000b003f7e60622f0sm2212389wmj.6.2023.06.08.07.35.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 07:35:50 -0700 (PDT) Date: Thu, 8 Jun 2023 07:35:48 -0700 From: Breno Leitao To: Paolo Abeni Cc: Kuniyuki Iwashima , alex.aring@gmail.com, andrea.righi@canonical.com, asml.silence@gmail.com, ast@kernel.org, axboe@kernel.dk, courmisch@gmail.com, davem@davemloft.net, dccp@vger.kernel.org, dsahern@kernel.org, edumazet@google.com, gnault@redhat.com, hbh25y@gmail.com, joannelkoong@gmail.com, kernelxing@tencent.com, kuba@kernel.org, leit@fb.com, linux-kernel@vger.kernel.org, linux-sctp@vger.kernel.org, linux-wpan@vger.kernel.org, lucien.xin@gmail.com, marcelo.leitner@gmail.com, martin.lau@kernel.org, martineau@kernel.org, matthieu.baerts@tessares.net, miquel.raynal@bootlin.com, mptcp@lists.linux.dev, netdev@vger.kernel.org, stefan@datenfreihafen.org, willemdebruijn.kernel@gmail.com, wojciech.drewek@intel.com Subject: Re: [PATCH net-next v6] net: ioctl: Use kernel memory on protocol ioctl callbacks Message-ID: References: <20230606180045.827659-1-leitao@debian.org> <20230607173142.86395-1-kuniyu@amazon.com> <5bd6ced877e97ac674d1308eab0b8d2107b7ab85.camel@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5bd6ced877e97ac674d1308eab0b8d2107b7ab85.camel@redhat.com> X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,FSL_HELO_FAKE, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 08, 2023 at 03:57:48PM +0200, Paolo Abeni wrote: > On Thu, 2023-06-08 at 01:43 -0700, Breno Leitao wrote: > > Hello Kuniyuki, > > On Wed, Jun 07, 2023 at 10:31:42AM -0700, Kuniyuki Iwashima wrote: > > > > +/* This is the most common ioctl prep function, where the result (4 bytes) is > > > > + * copied back to userspace if the ioctl() returns successfully. No input is > > > > + * copied from userspace as input argument. > > > > + */ > > > > +static int sock_ioctl_out(struct sock *sk, unsigned int cmd, void __user *arg) > > > > +{ > > > > + int ret, karg = 0; > > > > + > > > > + ret = sk->sk_prot->ioctl(sk, cmd, &karg); > > > > > > We need READ_ONCE(sk->sk_prot) as IPv4 conversion or ULP chnage could > > > occur at the same time. > > > > Thanks for the heads-up. I would like to pick you brain and understand > > a bit more about READ_ONCE() and what is the situation that READ_ONCE() > > will solve. > > AFAICS, in this specific case READ_ONCE() should not address any "real" > bug causing visible issue. > > Still the lack of it will likely cause syzkaller report for (harmless, > AFAICS) 'data races' around sk->sk_prot. We want to avoid such reports, > even if harmless, because they can end-up hiding more relevant bugs. > > > Is the situation related to when sock_ioctl_out() start to execute, and > > "sk->sk_prot" changes in a different thread? If that is the case, the > > arguments (cmd and arg) will be from the "previous" instance. > > > > Also, grepping for "sk->sk_prot->", I see more than a bunch of calls > > that do not use READ_ONCE() barrier. Why is this case different? > > Races on sk->sk_prot can happen only on inet6_stream_ops (due to ulp > and/or ADDRFORM) inet6_dgram_ops (due to ADDRFORM). AFAICS here > READ_ONCE() is needed as we can reach here via inet6_stream_ops- > >inet6_ioctl Thanks for the clarification, I will send a v6 with the READ_ONCE(). Breno