Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp832646pxb; Tue, 14 Sep 2021 09:38:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQSpir85Zpph+4HJQ5mPMJvU3EnWjAXnYaXynbPt7YT6iR5flm3GbWNbeUMbX0pOLawtjU X-Received: by 2002:a05:6512:24d:: with SMTP id b13mr4006087lfo.609.1631637529646; Tue, 14 Sep 2021 09:38:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631637529; cv=none; d=google.com; s=arc-20160816; b=q6oLcusgQf2BuxNDs0iy+KH/SXQXvKhS869kHoQmUVX0z+mCaqPxoip9Tv9AorAV/w a7MmdKYMR3dECvPrj0LSPckm2L6px3p6v7EUIS5cAJoyfG8wDS0XdZnAh22Hr+u4Jh2Z yi8FYnAuFT0tOjRmabwWuit4aUH7SeZnpFCtBwg7HBJnDC00or9NpQXwumNCMHZCSgr9 zyFXn9nBtJDbbHZY56sWchOOp3F3QEQd+Sk5OEyDbWaXCX9cwUHppJP3e6cYwmEDvpib ioGDxyV8uHHBAfGwcjXfB2kTbQUd0cPDlr5PiE00nKF2l42Ydd4c/i9RazLqMee+kjlX XPNw== 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=enCgZpYt6FX7J0pI+1xzEGtOUBSd7yOAWgJlnEngYZs=; b=igqF19mpeQfoJzJvUi6ivxr96lrC+/FaB/6iw1B9qGKl30pCet00B+ZQXl0r4c78i3 vYuAV0f7vmwZ1sgiJ+K2qFxRVSIK0K+ip+wIW9ZfMKe9DVxC5UO4SeA7adbNTztOnIJt GZBdOAOOgksXQuPQG6jdF2+H+fgB8WSownEPa84FKICvOG0/JwURQqfnx8+3WbWI1ODU XUsA7w+M17TMCVA+X/AQEXd2ELphSevqP0L5z7kRNlv7xw+Nfdgppo9DU42SGJinXfsm Uhung7FxWgxvRMpq3DrF6TjbWN74C6jK9WPOGPBTwaPhZHhwi/AkRiDDSXw4jx0TBLyh XDlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fieldses.org header.s=default header.b=aC3kjRbU; 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 f25si12770891lfq.118.2021.09.14.09.38.16; Tue, 14 Sep 2021 09:38:49 -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=aC3kjRbU; 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 S229617AbhINQjJ (ORCPT + 99 others); Tue, 14 Sep 2021 12:39:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230035AbhINQjJ (ORCPT ); Tue, 14 Sep 2021 12:39:09 -0400 Received: from fieldses.org (fieldses.org [IPv6:2600:3c00:e000:2f7::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 886AFC061574 for ; Tue, 14 Sep 2021 09:37:51 -0700 (PDT) Received: by fieldses.org (Postfix, from userid 2815) id 724F828E5; Tue, 14 Sep 2021 12:37:50 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.11.0 fieldses.org 724F828E5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fieldses.org; s=default; t=1631637470; bh=enCgZpYt6FX7J0pI+1xzEGtOUBSd7yOAWgJlnEngYZs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=aC3kjRbUV+J9P0rxNKB4ml4JSIHGm17avsPCFT8eauNheROSAh346cUmvZSOa0niD diEnhDIg8x5e2iE7UbHbYOmYe6huHtDTyzZy4IjR3XKc6g+Ri+clypeTOzLe62xsrU 7wnGatLFsfcWfKvQJ6/YEbbxJDJwXWSa9vXzQLRg= Date: Tue, 14 Sep 2021 12:37:50 -0400 From: Bruce Fields To: Jeff Layton Cc: Chuck Lever III , Dan Carpenter , Linux NFS Mailing List Subject: Re: [bug report] nfsd: Protect session creation and client confirm using client_lock Message-ID: <20210914163750.GB8134@fieldses.org> References: <20210907080732.GA20341@kili> <622EC724-ECBF-424D-A003-46A6B8E8C215@oracle.com> <20210908212605.GF23978@fieldses.org> <23A4CB30-F551-472F-9F2F-022C40AE1D70@oracle.com> <57B147B6-FC8F-4E70-A3E1-D449615B8355@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: "J. Bruce Fields" Subject: [PATCH] nfsd: don't alloc under spinlock in rpc_parse_scope_id Dan Carpenter says: The patch d20c11d86d8f: "nfsd: Protect session creation and client confirm using client_lock" from Jul 30, 2014, leads to the following Smatch static checker warning: net/sunrpc/addr.c:178 rpc_parse_scope_id() warn: sleeping in atomic context Reported-by: Dan Carpenter Fixes: d20c11d86d8f ("nfsd: Protect session creation and client...") Signed-off-by: J. Bruce Fields --- net/sunrpc/addr.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) On Thu, Sep 09, 2021 at 10:56:33AM -0400, Jeff Layton wrote: > Hmm, it sounds line in the second email he suggests using memcpy(): > > "Your "memcpy()" example implies that the source is always a fixed-size > thing. In that case, maybe that's the rigth thing to do, and you > should just create a real function for it." > > Maybe I'm missing the context though. > > In any case, when you're certain about the length of the source and > destination buffers, there's no real benefit to avoiding memcpy in favor > of strcpy and the like. It's just as correct. OK, queueing this up as is for 5.16 unless someone objects. (But, could really use testing, I'm not currently testing over ipv6.)--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, -- 2.31.1