Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp2951699rwo; Thu, 3 Aug 2023 18:47:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFdkeXI6tDUxZTgfXI0yGLO0/bzQlJYxaPtgZ3PUzvPJ5m5phkdw/I6Kd028m91gg35TYVV X-Received: by 2002:a17:907:2d2c:b0:974:fb94:8067 with SMTP id gs44-20020a1709072d2c00b00974fb948067mr473112ejc.23.1691113633821; Thu, 03 Aug 2023 18:47:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691113633; cv=none; d=google.com; s=arc-20160816; b=L4hY1rC4BgU5RGJ19ysIklU4QSglfB6uhXiJt8f+YWsJ+dGVOhaifWOc5S5HawP2Vg 7oN22Ru7YL79sSdlIfPcPawK/iqNgoP/SHt8sL3GLbjWlFa8ZDIF/2twMuar1xZSsl52 bo7xfSGANsEDuY2fm83ur2Hh3QYrIxoj80eVv5sLkyqcQesEis+G8K9OT0wiSGnxDQ1j BtgCpBYXUjavoa1Jly9BGNDxaozRBP7xZsPT6HmXSPuP4TGBkgh4kSfyUsGHCYwqigCW ogOS89sMtFf5ZaqLgTt+dAuwIAaenXOwJiZpIcmQMIgls7r1pSgw63cFQ2pegos3VJTM D8QA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=WbcIjoxeMxDSbeG8mSAp8iwqRQ0RT8jEmS9GGHCBSkU=; fh=YN/j01HQb/q4ETRZ6ZdCc0YF/divO9hjaFgDTBY2p5c=; b=08UJ7684/pT3EQR6TOBaqtmqKLw4WSa4yCd/5K7d1qy8RSzPPXvSd4rOXbbdTra0IU ybm6yk9f5uyHUa2eOZjscJXrfmsCWv/VlLVQsphWGx0NaV3k93h3iD3eT5PqQjXLC7Rb /RipodpG4+aclTCBK9ibmsnvNBH7AURjB/S77ZyQm8fOIDzSlRpb9oWSFHkZdx4L3dWL sQkfI7PrO/lGWzSAmeLt37IId3guZVDdJLfRe88sZa4/eKDsxqfHVkpqkUjTcTqi4s9x R6n4lpf+L1oU5Kq21si4VXq3Yrp+Vspfkdh1vEnHpbijWb0+ptB7E7TtrXSBLOj1XoB1 vBPg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-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 n23-20020a056402515700b005221dc07a73si819520edd.122.2023.08.03.18.46.38; Thu, 03 Aug 2023 18:47:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-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-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230294AbjHDB2X (ORCPT + 99 others); Thu, 3 Aug 2023 21:28:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229634AbjHDB2W (ORCPT ); Thu, 3 Aug 2023 21:28:22 -0400 Received: from mail.nfschina.com (unknown [42.101.60.195]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 1C70B423E; Thu, 3 Aug 2023 18:28:20 -0700 (PDT) Received: from localhost.localdomain (unknown [180.167.10.98]) by mail.nfschina.com (Maildata Gateway V2.8.8) with ESMTPA id E2C10602F96C4; Fri, 4 Aug 2023 09:28:06 +0800 (CST) X-MD-Sfrom: suhui@nfschina.com X-MD-SrcIP: 180.167.10.98 From: Su Hui To: trond.myklebust@hammerspace.com, anna@kernel.org, chuck.lever@oracle.com, jlayton@kernel.org, neilb@suse.de, kolga@netapp.com, Dai.Ngo@oracle.com, tom@talpey.com, nathan@kernel.org, ndesaulniers@google.com, trix@redhat.com Cc: bfields@fieldses.org, linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, kernel-janitors@vger.kernel.org, Su Hui Subject: [PATCH v2] fs: lockd: avoid possible wrong NULL parameter Date: Fri, 4 Aug 2023 09:26:57 +0800 Message-Id: <20230804012656.4091877-1-suhui@nfschina.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,RDNS_NONE, 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-nfs@vger.kernel.org clang's static analysis warning: fs/lockd/mon.c: line 293, column 2: Null pointer passed as 2nd argument to memory copy function. Assuming 'hostname' is NULL and calling 'nsm_create_handle()', this will pass NULL as 2nd argument to memory copy function 'memcpy()'. So return NULL if 'hostname' is invalid. Fixes: 77a3ef33e2de ("NSM: More clean up of nsm_get_handle()") Signed-off-by: Su Hui --- v2: - move NULL check to the callee "nsm_create_handle()" fs/lockd/mon.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/lockd/mon.c b/fs/lockd/mon.c index 1d9488cf0534..87a0f207df0b 100644 --- a/fs/lockd/mon.c +++ b/fs/lockd/mon.c @@ -276,6 +276,9 @@ static struct nsm_handle *nsm_create_handle(const struct sockaddr *sap, { struct nsm_handle *new; + if (!hostname) + return NULL; + new = kzalloc(sizeof(*new) + hostname_len + 1, GFP_KERNEL); if (unlikely(new == NULL)) return NULL; -- 2.30.2