From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8282BC433EF for ; Mon, 14 Feb 2022 09:40:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244102AbiBNJk0 (ORCPT ); Mon, 14 Feb 2022 04:40:26 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:33334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244509AbiBNJj4 (ORCPT ); Mon, 14 Feb 2022 04:39:56 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56E616548F; Mon, 14 Feb 2022 01:35:39 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5A14961161; Mon, 14 Feb 2022 09:35:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43019C340EF; Mon, 14 Feb 2022 09:35:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644831307; bh=GaNj9zRP1mg0t39tKG5gR6mk37qVTAHecl2hF5K82hw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jfM1XfGYujP7Uv4sVc/FmTnbUqdYDN1xAGKAGIPesh0+zNqUkGdUJ28FAS0szKK2v 3HzQLEHFfq2iIfrvCP/jYjhL03IqWiFl5im0DbXB4s/UBZvQpsCZ90DXQuQVC4buD5 lCPH0WAMd/ELbZIi0I7bAstYthHhe+eKXqjhT8qg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiaoke Wang , Anna Schumaker , Sasha Levin Subject: [PATCH 5.4 13/71] nfs: nfs4clinet: check the return value of kstrdup() Date: Mon, 14 Feb 2022 10:25:41 +0100 Message-Id: <20220214092452.474038846@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220214092452.020713240@linuxfoundation.org> References: <20220214092452.020713240@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Xiaoke Wang [ Upstream commit fbd2057e5329d3502a27491190237b6be52a1cb6 ] kstrdup() returns NULL when some internal memory errors happen, it is better to check the return value of it so to catch the memory error in time. Signed-off-by: Xiaoke Wang Signed-off-by: Anna Schumaker Signed-off-by: Sasha Levin --- fs/nfs/nfs4client.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/nfs/nfs4client.c b/fs/nfs/nfs4client.c index 8cace8350fa3d..3671a51fe5ebc 100644 --- a/fs/nfs/nfs4client.c +++ b/fs/nfs/nfs4client.c @@ -1293,8 +1293,11 @@ int nfs4_update_server(struct nfs_server *server, const char *hostname, } nfs_put_client(clp); - if (server->nfs_client->cl_hostname == NULL) + if (server->nfs_client->cl_hostname == NULL) { server->nfs_client->cl_hostname = kstrdup(hostname, GFP_KERNEL); + if (server->nfs_client->cl_hostname == NULL) + return -ENOMEM; + } nfs_server_insert_lists(server); return nfs_probe_destination(server); -- 2.34.1