From patchwork Mon Jan 6 13:17:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin King X-Patchwork-Id: 11319241 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F3F24138D for ; Mon, 6 Jan 2020 13:17:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DC5982072E for ; Mon, 6 Jan 2020 13:17:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726173AbgAFNRl (ORCPT ); Mon, 6 Jan 2020 08:17:41 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:44831 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726496AbgAFNRl (ORCPT ); Mon, 6 Jan 2020 08:17:41 -0500 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1ioSGE-0006Gv-IX; Mon, 06 Jan 2020 13:17:34 +0000 From: Colin King To: Trond Myklebust , Anna Schumaker , Scott Mayhew , David Howells , Al Viro , linux-nfs@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next] NFS: Add missing null check for failed allocation Date: Mon, 6 Jan 2020 13:17:34 +0000 Message-Id: <20200106131734.51759-1-colin.king@canonical.com> X-Mailer: git-send-email 2.24.0 MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Colin Ian King Currently the allocation of buf is not being null checked and a null pointer dereference can occur when the memory allocation fails. Fix this by adding a check and returning -ENOMEM. Addresses-Coverity: ("Dereference null return") Fixes: 6d972518b821 ("NFS: Add fs_context support.") Signed-off-by: Colin Ian King --- fs/nfs/nfs4namespace.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/nfs/nfs4namespace.c b/fs/nfs/nfs4namespace.c index 10e9e1887841..de6875a9b391 100644 --- a/fs/nfs/nfs4namespace.c +++ b/fs/nfs/nfs4namespace.c @@ -137,6 +137,9 @@ static int nfs4_validate_fspath(struct dentry *dentry, int n; buf = kmalloc(4096, GFP_KERNEL); + if (!buf) + return -ENOMEM; + path = nfs4_path(dentry, buf, 4096); if (IS_ERR(path)) { kfree(buf);