Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9304339ybi; Wed, 24 Jul 2019 01:45:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqxAMIBz20I0WEdA+0masEBKLWTSG2Zjc81m5QJvhDynzjZUaBLAIPKJllBFCvEQeFQdeaG4 X-Received: by 2002:a17:902:f213:: with SMTP id gn19mr87164247plb.35.1563957912988; Wed, 24 Jul 2019 01:45:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563957912; cv=none; d=google.com; s=arc-20160816; b=yErGCxDY+HO8PPPwHTs/dUcCt6ILBQM/IZeP6VePL8ltMVFuGrCGRYt946UCK3hzeP wDP2sECLEqVqLS3xj1gyAaLoW2RCUhjRDocjNIsR8STempgiSUl8nhMzQz+0cxsJLG7h SJNJZwk6HTqd3YhyCsbONHnskqzjgFVSLrYeGS2flAADTjlEcGFNDAV12QqZ+alMSIC/ Kj0fF7lLFM6M26UuacHNqix/sTkKS0VfUZ9fVCsO4/Uv2PkQOR1kQfRsl8ksktgMjm5v 8GF+KDyD2vdP7EttRyg6ShoA6EOwhsOt/nbQxYdCedEW58dgcRdBy3tq35WnT6527j7P m7Ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=0Ol/+/EACU1mDtCvpt+iEiYJ2SN+qSkf9suJGxid6UE=; b=J3CILE9vntm+D/6VMiQTb/VNvDhvTKSykaUVGJdHbKH0nhn/q7mpHNJ7gm+AItIOID Sg8oj9kughUX/OGalZkU7sYkSkaXxa8Pjb/9r6e8FFb3wtmzYru8jbQWfCYd6f6t9bsM GxWIt9s9lSIH7MUUPSrL1YyLMB3tF+iziuu/HAW/28DcnQKT59fxUWgd6LTGLfE+wgKN xpySi/tHufI/rPmFqtjFM0QK/GgkPNirvpIWjbM10MFkJ0g42XMZHJ1w9l3vcw642Si8 HYuOZDglgw7l+qFn20rtRG8mxNRo93DpMOmiDckWKEOrXprQzite+cz6z2AcImm7yvFQ Rhwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PiEquNkH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j95si12422470plb.349.2019.07.24.01.44.58; Wed, 24 Jul 2019 01:45:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PiEquNkH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726277AbfGXInK (ORCPT + 99 others); Wed, 24 Jul 2019 04:43:10 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:42610 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725883AbfGXInK (ORCPT ); Wed, 24 Jul 2019 04:43:10 -0400 Received: by mail-pg1-f193.google.com with SMTP id t132so20851820pgb.9 for ; Wed, 24 Jul 2019 01:43:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=0Ol/+/EACU1mDtCvpt+iEiYJ2SN+qSkf9suJGxid6UE=; b=PiEquNkHK4nn2WkH3wqswaX9lLCPjHym9g95ww2KLH/+5cwz42kzG42PyZffZ4u8zr hY4UppU3tgKNFFllYQGmGoB2Cdl4Bo6mwJckc2WpR2Wyt2cqyIk9YB1uWh6FFnG4ZAzd ir/Y6ME74fPSJFnWvYY0JP7Lz2N2+cLCeGCkyARvfY6Zdfbgw/zUA+gmz6hT19YHLxfu 9WfM+WAw0KTdkqe+v2FJ/V+9ustDnksRcKKwKHkrDxUar3BWDQeg5XWlg3L6DYgUqQ3u ZqzbeT2MwR+J0BWRPH6lTCagRChanNSYZxRH3I45eviZTovR7+jdqUFIUOgCoDQ7b/XY +KnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=0Ol/+/EACU1mDtCvpt+iEiYJ2SN+qSkf9suJGxid6UE=; b=Pw7Jicp5AKB3tnIc49wIPP3vaDIvFgb4i+imVi/Es/xi9g4GUnDTT5aTWxhewYJe76 WFAnBU/uEJsPTFfDDOsMEl1a1+zeSPLsGCb5uJUH+qcCFG6zedhrXfPfuBQjf+5zfLTe EnEmQgPJr+u8G072EcTdeaKsatNvJYnavkdz6Prc9f7mDJln5scwzt5kSHzyIisPxMBB lAoJC0RLwKO3r/VVJWdnpR+6dwVuZAsbz7Gynl83vW39GsZbOKWIWPXFJ2DJFKFxKiPZ vwLJBYQDSvto1KcFU9OmlxKLYTvZKOkebrjKGKX1b0g7c47lghMvAzc72lyFIy1tBjaH rExQ== X-Gm-Message-State: APjAAAUr6FIJlG7p+PRnH6/C3YGTq2nJxnTDrrEmuqu88jC75bLePPJT MYI86d0u/Cxw6EwNOLmvHQzDeBW6+t4= X-Received: by 2002:a62:8c81:: with SMTP id m123mr10114404pfd.240.1563957789574; Wed, 24 Jul 2019 01:43:09 -0700 (PDT) Received: from oslab.tsinghua.edu.cn ([2402:f000:4:72:808::3ca]) by smtp.gmail.com with ESMTPSA id r15sm49326364pfh.121.2019.07.24.01.43.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Jul 2019 01:43:09 -0700 (PDT) From: Jia-Ju Bai To: rpeterso@redhat.com, agruenba@redhat.com Cc: cluster-devel@redhat.com, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] fs: gfs2: Fix a null-pointer dereference in gfs2_alloc_inode() Date: Wed, 24 Jul 2019 16:43:03 +0800 Message-Id: <20190724084303.1236-1-baijiaju1990@gmail.com> X-Mailer: git-send-email 2.17.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In gfs2_alloc_inode(), when kmem_cache_alloc() on line 1724 returns NULL, ip is assigned to NULL. In this case, "return &ip->i_inode" will cause a null-pointer dereference. To fix this null-pointer dereference, NULL is returned when ip is NULL. This bug is found by a static analysis tool STCheck written by us. Signed-off-by: Jia-Ju Bai --- fs/gfs2/super.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index 0acc5834f653..c07c3f4f8451 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c @@ -1728,8 +1728,9 @@ static struct inode *gfs2_alloc_inode(struct super_block *sb) memset(&ip->i_res, 0, sizeof(ip->i_res)); RB_CLEAR_NODE(&ip->i_res.rs_node); ip->i_rahead = 0; - } - return &ip->i_inode; + return &ip->i_inode; + } else + return NULL; } static void gfs2_free_inode(struct inode *inode) -- 2.17.0