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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91CD9CDB47E for ; Wed, 18 Oct 2023 15:15:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E67518D015D; Wed, 18 Oct 2023 11:15:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E179E8D0016; Wed, 18 Oct 2023 11:15:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CDF268D015D; Wed, 18 Oct 2023 11:15:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id BF05D8D0016 for ; Wed, 18 Oct 2023 11:15:53 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 92A4D1A0CA4 for ; Wed, 18 Oct 2023 15:15:53 +0000 (UTC) X-FDA: 81358932186.09.B9F9E20 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf18.hostedemail.com (Postfix) with ESMTP id 7B48A1C0025 for ; Wed, 18 Oct 2023 15:15:50 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SeAHo+ss; spf=pass (imf18.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697642150; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=jB/qQDYRlrSDUxpltmB2o5vEp1zK7M2ILhY2l9aeHL8=; b=tN27Ns9+OqZtQKoc8P517M9JbGo1ryC0xZxM5cwJbj3CTSmx5I3wHYuo1c7oY1AHZpxfEE wFLZv+YfpNY6eBXdWvsL5cySqjq+mkg6gebDewTE2krqesu4i+mHfs4uk7Cgf+a8IclFn8 urV2Gye0XSB364K0Sxzvj2PW+Mrj+Fk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697642150; a=rsa-sha256; cv=none; b=2sbn8t679NuIUNn2t60Ma8MQMhcJLOH1IHF1xif9m3wOCZOOnRBDkLkrhlOjiSTEL9iZyi FtkmhVUAvX1dQy0vHWeYsYclvLhXa88+PD7SFYExYOE1sB/Rsv2mXDEhXVdXxypuuStaBA jq2tAdfRT9DSWaNr0YZRZLRBFxyWvTo= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SeAHo+ss; spf=pass (imf18.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697642149; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=jB/qQDYRlrSDUxpltmB2o5vEp1zK7M2ILhY2l9aeHL8=; b=SeAHo+ssvwWAPdm8HMNGW5nNHGOkcMo27Pxb8TmLSF5QIWri+JjidkwJH0frCfzY7CvMK/ vCFNGpmbf5sDoFa9Yl3ydhyUGyK5OdMAGU2A+d4txXL0nyaVT772WdOrKdeAazZWWX6e6L Zk/GxwBgPHnN5+msu6lCYt76yvyeRNI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-288-n3af-Y9sMfyzzG8I4WAiZQ-1; Wed, 18 Oct 2023 11:15:35 -0400 X-MC-Unique: n3af-Y9sMfyzzG8I4WAiZQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 08C60185A795; Wed, 18 Oct 2023 15:15:35 +0000 (UTC) Received: from localhost (unknown [10.72.112.83]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4DF9E492BEF; Wed, 18 Oct 2023 15:15:33 +0000 (UTC) Date: Wed, 18 Oct 2023 23:15:31 +0800 From: Baoquan He To: Dan Carpenter , Philip Li Cc: oe-kbuild@lists.linux.dev, Lorenzo Stoakes , lkp@intel.com, oe-kbuild-all@lists.linux.dev, linux-kernel@vger.kernel.org, Andrew Morton , Linux Memory Management List Subject: Re: mm/vmalloc.c:3689 vread_iter() error: we previously assumed 'vm' could be null (see line 3667) Message-ID: References: <89caf59a-d3b9-409d-b1ae-9e370cb9ee7d@kadam.mountain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Stat-Signature: ub9porfipwgipip4a9c94rweab55qn45 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 7B48A1C0025 X-Rspam-User: X-HE-Tag: 1697642150-686822 X-HE-Meta: U2FsdGVkX19GgtKBN117ggm8PON60+RUnNIUO+3iSoS4TVgppGRSCc1nWhynWGvioOBkaL5zqruV0YNMyfe44jH4XuwUlLB5Jl4SSehsuE3s5yZTY6ts50/F9vBTlEN0maOT1aMv8mgD+LwRKJBEmAOurhfh1N4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omqSh25R0/d2z9R7/WSV2swNBtVY5XW7nLc+4UeB7crZtbdpZ01tr7XP2CjZVRAWqJS8bC0MddGSm+8VK+Gs02yjDNX8eFeKguZGXMljUWOCy4uoMbSS5+Dq9TUHabDw25uEUm4eHUEdfAU9PiGOAFdF7BqRoKtkHM8809GQ+p4dkpkCuKN1hpFjpwr6pQY4QDdZ7pWw7C+52b7mhacNHoepYC2R8wCjtYZ8nsRdRqFv5v9rxHAro0XuYjyGL9fN51DzRYTA+1jY0/jSt3mnlVeqliec7WLlrLC+Jw== 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 10/18/23 at 08:45pm, Philip Li wrote: > On Wed, Oct 18, 2023 at 08:12:30PM +0800, Baoquan He wrote: > > Hi Dan, > > > > On 10/18/23 at 01:32pm, Dan Carpenter wrote: > > > On Wed, Oct 18, 2023 at 04:54:33PM +0800, Baoquan He wrote: > > > > Hi, > > > > > > > > On 10/17/23 at 05:26pm, Dan Carpenter wrote: > > > > > tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master > > > > > head: 213f891525c222e8ed145ce1ce7ae1f47921cb9c > > > > > commit: 4c91c07c93bbbdd7f2d9de2beb7ee5c2a48ad8e7 mm: vmalloc: convert vread() to vread_iter() > > > > > config: x86_64-allnoconfig (https://download.01.org/0day-ci/archive/20231017/202310171600.WCrsOwFj-lkp@intel.com/config) > > > > > compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 > > > > > reproduce: (https://download.01.org/0day-ci/archive/20231017/202310171600.WCrsOwFj-lkp@intel.com/reproduce) > > > > > > > > > > If you fix the issue in a separate patch/commit (i.e. not just a new version of > > > > > the same patch/commit), kindly add following tags > > > > > | Reported-by: kernel test robot > > > > > | Reported-by: Dan Carpenter > > > > > | Closes: https://lore.kernel.org/r/202310171600.WCrsOwFj-lkp@intel.com/ > > > > > > > > > > smatch warnings: > > > > > mm/vmalloc.c:3689 vread_iter() error: we previously assumed 'vm' could be null (see line 3667) > > > > > > > > I see the code deficit, while the reproduce link seems to be unavilable. > > > > Could you double check the link and provide a good one so that I can > > > > verify the code fix? > > > > > > Here's a link. :) > > > > > > https://repo.or.cz/smatch.git/blob/HEAD:/Documentation/smatch.txt > > > > > > Just build it and run: > > > > > > ~/smatch/smatch_scripts/kchecker drivers/whatever/file.c > > > > I don't know smatch and lkp well, and have no idea on how to use above > > Hi Baoquan, sorry there's issue in the generation of reproduce step, but even > it is generated, it doesn't contain the detail to setup smatch. You can follow > the smatch.txt to do the setup. > > > smatch.txt to build the target file.c. I meant in this lkp report, the > > config file is available, however, the reproduce file is empty. Could > > you help add an available reproduce file link? or give a little more > > detail guiding me how to make use of above smatch file to build .c file? > > On the other side, Dan has added analysis to the report as below. > It's possible to resolve the issue without running the smatch check. > You can give this a try. > > 06c8994626d1b7 Baoquan He 2023-02-06 3657 if (!vm && !flags) > > NULL check > > ... > > 06c8994626d1b7 Baoquan He 2023-02-06 @3689 else if (!(vm->flags & VM_IOREMAP)) > ^^^^^^^^^ > Unchecked dereference Thanks for the detailed explanation, Philipp. Yes, the code deficit is identified. I planned to reproduce and verify with LKP's reproducer so that it's 100% clear. Anyway, below patch should fix it. >From a39fdd50030a7d88a7f69bcba29e6f75020a1915 Mon Sep 17 00:00:00 2001 From: Baoquan He Date: Wed, 18 Oct 2023 22:50:14 +0800 Subject: [PATCH] mm/vmalloc: fix the unchecked dereference warning in vread_iter() Content-type: text/plain LKP reported smatch warning as below: =================== smatch warnings: mm/vmalloc.c:3689 vread_iter() error: we previously assumed 'vm' could be null (see line 3667) ...... 06c8994626d1b7 @3667 size = vm ? get_vm_area_size(vm) : va_size(va); ...... 06c8994626d1b7 @3689 else if (!(vm->flags & VM_IOREMAP)) ^^^^^^^^^ Unchecked dereference ===================== So add checking on whether 'vm' is not null when dereferencing it in vread_iter(). This mutes smatch complaint. Reported-by: kernel test robot Reported-by: Dan Carpenter Closes: https://lore.kernel.org/r/202310171600.WCrsOwFj-lkp@intel.com/ Signed-off-by: Baoquan He --- mm/vmalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index aad48ed8d86b..2cc992392db7 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3813,7 +3813,7 @@ long vread_iter(struct iov_iter *iter, const char *addr, size_t count) if (flags & VMAP_RAM) copied = vmap_ram_vread_iter(iter, addr, n, flags); - else if (!(vm->flags & VM_IOREMAP)) + else if (!(vm && (vm->flags & VM_IOREMAP))) copied = aligned_vread_iter(iter, addr, n); else /* IOREMAP area is treated as memory hole */ copied = zero_iter(iter, n); -- 2.41.0