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 X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 121A3C2BB55 for ; Tue, 7 Apr 2020 18:19:12 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CC5C320768 for ; Tue, 7 Apr 2020 18:19:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CC5C320768 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 624CF8E0005; Tue, 7 Apr 2020 14:19:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5D4D88E0001; Tue, 7 Apr 2020 14:19:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 511708E0005; Tue, 7 Apr 2020 14:19:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0094.hostedemail.com [216.40.44.94]) by kanga.kvack.org (Postfix) with ESMTP id 376258E0001 for ; Tue, 7 Apr 2020 14:19:11 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id EF9FE801B597 for ; Tue, 7 Apr 2020 18:19:10 +0000 (UTC) X-FDA: 76681870860.19.frog15_5019b7cc2c849 X-HE-Tag: frog15_5019b7cc2c849 X-Filterd-Recvd-Size: 2770 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Tue, 7 Apr 2020 18:19:10 +0000 (UTC) IronPort-SDR: iIMo+q+l7tHSN1CjmC5rstAaLMiNxSh02fmO2pt1YQ5pyAIjXohX2qdihp2133FSz6ijdHubtU trtIV4kvqjUw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2020 11:19:08 -0700 IronPort-SDR: hrIdburDaMCzTAQyPcSF6hxKn0vdzYIyj0JgJyyQtUugCGrjCw8SK7PRdi+nBnpzQcRmt5bpho ZdVHFyZ+P7BA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,356,1580803200"; d="scan'208";a="451317416" Received: from iweiny-desk2.sc.intel.com ([10.3.52.147]) by fmsmga005.fm.intel.com with ESMTP; 07 Apr 2020 11:19:08 -0700 Date: Tue, 7 Apr 2020 11:19:08 -0700 From: Ira Weiny To: Miles Chen Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, wsd_upstream@mediatek.com Subject: Re: [PATCH] mm/gup: fix null pointer dereference detected by coverity Message-ID: <20200407181908.GB94792@iweiny-DESK2.sc.intel.com> References: <20200407095107.1988-1-miles.chen@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200407095107.1988-1-miles.chen@mediatek.com> User-Agent: Mutt/1.11.1 (2018-12-01) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Apr 07, 2020 at 05:51:07PM +0800, Miles Chen wrote: > In fixup_user_fault(), it is possible that unlocked is NULL, > so we should test unlocked before using it. > > For example, in arch/arc/kernel/process.c, NULL is passed > to fixup_user_fault(). > > SYSCALL_DEFINE3(arc_usr_cmpxchg, int *, uaddr, int, expected, int, new) > { > ... > ret = fixup_user_fault(current, current->mm, (unsigned long) uaddr, > FAULT_FLAG_WRITE, NULL); > ... > } > > Fixes: 4a9e1cda2748 ("mm: bring in additional flag for fixup_user_fault to signal unlock") > Signed-off-by: Miles Chen Reviewed-by: Ira Weiny > --- > mm/gup.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/mm/gup.c b/mm/gup.c > index da3e03185144..a68d11dc232d 100644 > --- a/mm/gup.c > +++ b/mm/gup.c > @@ -1230,7 +1230,8 @@ int fixup_user_fault(struct task_struct *tsk, struct mm_struct *mm, > if (ret & VM_FAULT_RETRY) { > down_read(&mm->mmap_sem); > if (!(fault_flags & FAULT_FLAG_TRIED)) { > - *unlocked = true; > + if (unlocked) > + *unlocked = true; > fault_flags |= FAULT_FLAG_TRIED; > goto retry; > } > -- > 2.18.0