From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 01FE03AC0C for ; Wed, 20 Sep 2023 12:31:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 74E11C433CD; Wed, 20 Sep 2023 12:31:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1695213064; bh=GUecnBtGvksMdvIp3OwF13TnKiA0wZfgTRPEIQ7i/A4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KVusYpu96E+kPNNKueQmrOmscZm2h83FAg1y+hCuz4F61L+EbEpgHR/aCbMYb+IYc 4OB0e+FqHgDVcLFIEpMPhf2K1wzqu66OGzV2OddxkeUqOSixnYSXklul7ZY2jeJUws XTns9tgjzST1kpAe36LyumfrlF6bkwnLXlSFgB+Q= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Su Hui , Nick Desaulniers , Jeff Layton , Chuck Lever , Sasha Levin Subject: [PATCH 5.4 147/367] fs: lockd: avoid possible wrong NULL parameter Date: Wed, 20 Sep 2023 13:28:44 +0200 Message-ID: <20230920112902.477408645@linuxfoundation.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230920112858.471730572@linuxfoundation.org> References: <20230920112858.471730572@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Su Hui [ Upstream commit de8d38cf44bac43e83bad28357ba84784c412752 ] 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 Reviewed-by: Nick Desaulniers Reviewed-by: Jeff Layton Signed-off-by: Chuck Lever Signed-off-by: Sasha Levin --- fs/lockd/mon.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/lockd/mon.c b/fs/lockd/mon.c index 1eabd91870e6f..d770a41f85695 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.40.1