Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp866571pxb; Wed, 8 Sep 2021 14:27:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyQAOlFOThE2rlO7QGRgEjgAJ+TJgwHqTD27WJINmknmbSK1GOr7z7S8vzTcqXNy47pffo X-Received: by 2002:a05:6e02:20c3:: with SMTP id 3mr228033ilq.139.1631136440157; Wed, 08 Sep 2021 14:27:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631136440; cv=none; d=google.com; s=arc-20160816; b=UHWCuK+U7quMtWFuk52XpHcnysXnebiAmU3tqjEy/4WF8qlt7lTKho4BoZ2unHRWnh xnX9lyYd+d6QTOuBPyEhKGH9ZXNZNt8aJjYnWd07RmW20Q5q1algXkHoXfuzivSSKLap o/vCCTSZ6OIOPmzCzs7NBNtOJzjL25HMtSq/o4Ohtv2b2zoyK0hVRy8DSVoGlsG8jMJd E1HxROa+nz+ApM6s6HX7cn1Fj9ZSE+PQtjDlDbyUQ2jWWZvFWS/Ao1JPU7X6mDEUYTYE 4LHAfq1oZYSa0CDOhK7M8MkhFGR/aO0sxJU5EQEWfJkv5ywmPyADzgE2y2a+tQ2LDwak edAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:dkim-filter; bh=lwLbs160re0AuNnzwL9YajBsZwg0P/fJ7LxV8NwO//o=; b=eC3i2sXHut4LmfX8U1pib7i/R+fo2EmO08TwY+cGuDeRoZA5h4COr5XsYlQTzy96Qb a2zBClOlYARZBA0GOqWsZaudvG71kTOJ1d3U5EEPGQSzYfzgcEGnev52hVcayXYVaCXV Y72JI9XwYz1hf5qupWLe4Ae4cFZONTVCgbpaKGUvU8aFCq/ealC2Kq3JZXp4fAhkhs5h 9srXk4CxIiZOarQ/+3k0gLsSl52L8xoMoJXS4twO3F0BqLhWa2EeHRNPFBa3CmCO1fcw KQHWMSmLKVlvAj4UcBmPKV/zj56nUmHnh+9OujBi2kdGIhhEWIjYz0povhIWV31HAGo/ z8bA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fieldses.org header.s=default header.b=dr3jKJUy; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h25si338812ioj.39.2021.09.08.14.26.55; Wed, 08 Sep 2021 14:27:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-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=@fieldses.org header.s=default header.b=dr3jKJUy; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349865AbhIHV1O (ORCPT + 99 others); Wed, 8 Sep 2021 17:27:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231956AbhIHV1O (ORCPT ); Wed, 8 Sep 2021 17:27:14 -0400 Received: from fieldses.org (fieldses.org [IPv6:2600:3c00:e000:2f7::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C205C061575 for ; Wed, 8 Sep 2021 14:26:06 -0700 (PDT) Received: by fieldses.org (Postfix, from userid 2815) id 88DEB6CD0; Wed, 8 Sep 2021 17:26:05 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.11.0 fieldses.org 88DEB6CD0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fieldses.org; s=default; t=1631136365; bh=lwLbs160re0AuNnzwL9YajBsZwg0P/fJ7LxV8NwO//o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=dr3jKJUyGUPG2dPSrEBcjOVk4Y3/QKRNtLKWqqlXt0l2EhcWhi1hX90JGEPV9Qxyb 5AwlQU8KR3EXWgrGeJuGMiSYF5bUfPixnNqTR2MBSlxQ5tpdod7fM78uQTJXEFX93V TgggJmkmyt961RAQcASGZW00x4/5RWE3Tk6rkC4A= Date: Wed, 8 Sep 2021 17:26:05 -0400 From: Bruce Fields To: Chuck Lever III Cc: Jeff Layton , Dan Carpenter , Linux NFS Mailing List Subject: Re: [bug report] nfsd: Protect session creation and client confirm using client_lock Message-ID: <20210908212605.GF23978@fieldses.org> References: <20210907080732.GA20341@kili> <622EC724-ECBF-424D-A003-46A6B8E8C215@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <622EC724-ECBF-424D-A003-46A6B8E8C215@oracle.com> User-Agent: Mutt/1.5.21 (2010-09-15) Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org On Tue, Sep 07, 2021 at 03:00:23PM +0000, Chuck Lever III wrote: > We have IPV6_SCOPE_ID_LEN as a maximum size of the scope ID, > and it's not a big value. As long as boundary checking is made > to be sufficient, then a stack residency for the device name > should be safe. Something like this? (Or are you making a patch? I'm not even sure how to test.) --b. diff --git a/net/sunrpc/addr.c b/net/sunrpc/addr.c index 6e4dbd577a39..d435bffc6199 100644 --- a/net/sunrpc/addr.c +++ b/net/sunrpc/addr.c @@ -162,8 +162,10 @@ static int rpc_parse_scope_id(struct net *net, const char *buf, const size_t buflen, const char *delim, struct sockaddr_in6 *sin6) { - char *p; + char p[IPV6_SCOPE_ID_LEN + 1]; size_t len; + u32 scope_id = 0; + struct net_device *dev; if ((buf + buflen) == delim) return 1; @@ -175,29 +177,23 @@ static int rpc_parse_scope_id(struct net *net, const char *buf, return 0; len = (buf + buflen) - delim - 1; - p = kmemdup_nul(delim + 1, len, GFP_KERNEL); - if (p) { - u32 scope_id = 0; - struct net_device *dev; - - dev = dev_get_by_name(net, p); - if (dev != NULL) { - scope_id = dev->ifindex; - dev_put(dev); - } else { - if (kstrtou32(p, 10, &scope_id) != 0) { - kfree(p); - return 0; - } - } - - kfree(p); - - sin6->sin6_scope_id = scope_id; - return 1; + if (len > IPV6_SCOPE_ID_LEN) + return 0; + + memcpy(p, delim + 1, len); + p[len] = 0; + + dev = dev_get_by_name(net, p); + if (dev != NULL) { + scope_id = dev->ifindex; + dev_put(dev); + } else { + if (kstrtou32(p, 10, &scope_id) != 0) + return 0; } - return 0; + sin6->sin6_scope_id = scope_id; + return 1; } static size_t rpc_pton6(struct net *net, const char *buf, const size_t buflen,