Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4478846ybx; Mon, 4 Nov 2019 14:06:32 -0800 (PST) X-Google-Smtp-Source: APXvYqxM3y0r3gXAPgkseXasRAil+EXgcT7sMlH+lTZwkOrXKyZlXmpAvGwKex2zqXTmQHC3F3Jy X-Received: by 2002:a17:906:22c9:: with SMTP id q9mr1294904eja.198.1572905192107; Mon, 04 Nov 2019 14:06:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572905192; cv=none; d=google.com; s=arc-20160816; b=tDG6AHe41ccV+vzQNxYdYTkH7O4QPBsLLROoyYekBKfNr6On+z2VvcHtD8xWKw1/42 hB+5L5rr/lGbptjcLK13dkkmZspoEhtsMspF8qVb3gd5URdD5Vf1IBzpNRxhtRwiDIIi 918FXj4Nqx5dKnCSOG9Vq28cew5LXSTW2Di1D113OWxWZw7rgXYoods49zIpVM9KYaEU zPxPT7pe/Ix7NVqI67xCXhyJu8dtQ+Zg01fVB82Vi/p3/7tKH2KAzSBE5tmYgy5UOiUn RJ7Vc0cgdHAWmPOJS3mqKqIJxexk6iV+rySYTpfMpDkoiOojfm07wihVBhRc0LmcjNra nHWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZcMUoCFkJTm+8SKgeHwfu4Je9TqokliJmMqe9hr80tI=; b=LxL97sIDEvFvuR5NLOiY+qsjSgNexXkqb0xUsyjzvPLiQAQeib1BcNNDTtfUadzBM6 8MmpTerJtQo+S9fvTB8/P4/khK4dU4MiJ6V0Zrb09rnsb2stF9f3NEBfFl62ilezhhwC d6ukFJBPn4IviIUf37EKddfpy1zCyCbX/kTEtq5yme52GR3WWljKBwgseNHgbFeDmjtV eCJk1K0OQ4EOGbjz+XgJSPNO4Owlhzs1DzK02TgoIomJCG9cS5RO6zWPC5ZATxKRIFPu spTMkxzlUJalYEcFYDGaF6AR1Pucw7W3+twJWdzQZpXA0OgHKjTZ070hnBhyzUYDBOna Q4aQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=O4k9U5cV; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t21si9136648edi.123.2019.11.04.14.06.05; Mon, 04 Nov 2019 14:06:32 -0800 (PST) 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=@kernel.org header.s=default header.b=O4k9U5cV; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389377AbfKDWCl (ORCPT + 99 others); Mon, 4 Nov 2019 17:02:41 -0500 Received: from mail.kernel.org ([198.145.29.99]:32796 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388532AbfKDWCj (ORCPT ); Mon, 4 Nov 2019 17:02:39 -0500 Received: from localhost (6.204-14-84.ripe.coltfrance.com [84.14.204.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B3486205C9; Mon, 4 Nov 2019 22:02:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572904959; bh=w406F0HmU4jhcRSyeci8vZ/7K4lSmXJWWg2uxt+sgdM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O4k9U5cVQp3hWs9bsvRth7ONsyYVpuQfQvGKW/brs6Il7Tc6v2eL2+kDTCyJGPNdW WPWHP3CFyG3lqoYx1UUkZOCrg/mkCPPVnJFptbTXcMsJzIJVEiHtXYlzMnM3GfKdLZ h8ky9RtZiBQoYdemRnZHQ6Pyb7Jttp9q7WUzwW+k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jia-Ju Bai , Joseph Qi , Mark Fasheh , Joel Becker , Junxiao Bi , Changwei Ge , Gang He , Jun Piao , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 4.19 087/149] fs: ocfs2: fix a possible null-pointer dereference in ocfs2_write_end_nolock() Date: Mon, 4 Nov 2019 22:44:40 +0100 Message-Id: <20191104212142.628260397@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104212126.090054740@linuxfoundation.org> References: <20191104212126.090054740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jia-Ju Bai [ Upstream commit 583fee3e12df0e6f1f66f063b989d8e7fed0e65a ] In ocfs2_write_end_nolock(), there are an if statement on lines 1976, 2047 and 2058, to check whether handle is NULL: if (handle) When handle is NULL, it is used on line 2045: ocfs2_update_inode_fsync_trans(handle, inode, 1); oi->i_sync_tid = handle->h_transaction->t_tid; Thus, a possible null-pointer dereference may occur. To fix this bug, handle is checked before calling ocfs2_update_inode_fsync_trans(). This bug is found by a static analysis tool STCheck written by us. Link: http://lkml.kernel.org/r/20190726033705.32307-1-baijiaju1990@gmail.com Signed-off-by: Jia-Ju Bai Reviewed-by: Joseph Qi Cc: Mark Fasheh Cc: Joel Becker Cc: Junxiao Bi Cc: Changwei Ge Cc: Gang He Cc: Jun Piao Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- fs/ocfs2/aops.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c index dc773e163132c..543efa3e5655f 100644 --- a/fs/ocfs2/aops.c +++ b/fs/ocfs2/aops.c @@ -2056,7 +2056,8 @@ out_write_size: inode->i_mtime = inode->i_ctime = current_time(inode); di->i_mtime = di->i_ctime = cpu_to_le64(inode->i_mtime.tv_sec); di->i_mtime_nsec = di->i_ctime_nsec = cpu_to_le32(inode->i_mtime.tv_nsec); - ocfs2_update_inode_fsync_trans(handle, inode, 1); + if (handle) + ocfs2_update_inode_fsync_trans(handle, inode, 1); } if (handle) ocfs2_journal_dirty(handle, wc->w_di_bh); -- 2.20.1