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 C9A4BCDB465 for ; Thu, 19 Oct 2023 12:55:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 56F3E8D01A2; Thu, 19 Oct 2023 08:55:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 51FBD8D019E; Thu, 19 Oct 2023 08:55:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E7B88D01A2; Thu, 19 Oct 2023 08:55:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 2DD768D019E for ; Thu, 19 Oct 2023 08:55:59 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 07069A02D3 for ; Thu, 19 Oct 2023 12:55:59 +0000 (UTC) X-FDA: 81362208438.05.4667FDF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 215A140012 for ; Thu, 19 Oct 2023 12:55:56 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=CPz54tir; spf=pass (imf11.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697720157; a=rsa-sha256; cv=none; b=Ugwp7zeTTQRAWOMnmetFvjgZ2VARw8m9zSW8E8baoemOXGC1t2QStsY7gkS1n718aVFcT/ GKHd1MQjaghBHF0+J2xbfvw3m+GDrpgVwBody7sopnIyZahdnc7z+gDSfW5Ccuti3ORl0d rQx+vMLzmbenJ8p3AgF5ZlqgTtNT29E= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=CPz54tir; spf=pass (imf11.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.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=1697720157; 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=bedN9QfTANJGNML2vYFMLodX6ICVGSptHlSOlZaBF4c=; b=thG+femWKrLEos6JQ80tsJXXvjo49h2oMZrgKKo/jx5BN5Q1of+0x8kgcYyJdoXW0ePgo8 fuRlQTrwVzN6YdC+zFlPhtdd4BGhmxQZcwILqL8vIxpYeMorMjZPSbgtGkTFhBmYzDSyh0 HcWFwCau5kNJPy9YaeTdxtdSx8b+PIg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697720156; 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=bedN9QfTANJGNML2vYFMLodX6ICVGSptHlSOlZaBF4c=; b=CPz54tirVxWMQWVMm7+LZq4mWLmrAYXsYurjhRLGzEahHofzJZRhx4vSOtPz+dvs70hYI/ TevlekOCljAxLhhRn5GQp/IgdbH6zu1O9nATLNI8iDHX1JV4et2xDOwiY3izeRDJnxSiRL ceJDCn/JEAGTYW0Tc981f9kR3g6Ljtk= 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-9-2BE9P6GuMxSTIDTMyZSV4g-1; Thu, 19 Oct 2023 08:55:54 -0400 X-MC-Unique: 2BE9P6GuMxSTIDTMyZSV4g-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 2A4A782DFB8; Thu, 19 Oct 2023 12:55:54 +0000 (UTC) Received: from localhost (unknown [10.72.112.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 76CA91C060AE; Thu, 19 Oct 2023 12:55:53 +0000 (UTC) Date: Thu, 19 Oct 2023 20:55:50 +0800 From: Baoquan He To: Dan Carpenter Cc: Andrew Morton , Philip Li , oe-kbuild@lists.linux.dev, Lorenzo Stoakes , lkp@intel.com, oe-kbuild-all@lists.linux.dev, linux-kernel@vger.kernel.org, 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> <20231018085248.6f3f36101cbdfe0990c8b467@linux-foundation.org> <0eddb8b4-47a1-4d94-ae44-707addae77c8@kadam.mountain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0eddb8b4-47a1-4d94-ae44-707addae77c8@kadam.mountain> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 215A140012 X-Stat-Signature: koymxe7ae83eri3fxenmahuxzhqod5fy X-Rspam-User: X-HE-Tag: 1697720156-320987 X-HE-Meta: U2FsdGVkX1/PiJ9e8fRLelr60xgfjHuPk2Z+Dwq2KCBV6FyphSPks9p+7EULeWMr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pLAFfUJLrhCoK9+FW8esVrvv//pD0wM9BurzVFb9cWD1mXyUPdHR9/u5SdiGFGIrZgMoDq/4BU34mNqaU3el09TjRv9XWomHDJgy3gWH6TD4pwCuraGadRX0= 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/19/23 at 08:40am, Dan Carpenter wrote: > On Thu, Oct 19, 2023 at 10:28:21AM +0800, Baoquan He wrote: > > On 10/18/23 at 08:52am, Andrew Morton wrote: > > > On Wed, 18 Oct 2023 23:15:31 +0800 Baoquan He wrote: > > > > > > > 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. > > > > > > > > ... > > > > > > > > --- 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); > > > > > > So is this not a real runtime bug? We're only doing this to suppress a > > > smatch warning? > > > > > > If so, can we please include a description of *why* this wasn't a bug? > > > What conditions ensure that vm!=NULL at this point? > > > > I think this is not a real runtime bug. The only chance it can hapen is > > when (flags == VMAP_BLOCK) is true. That has been warned and could never > > happen. I updated patch log and paste v2 here. > > > > /* > > * VMAP_BLOCK indicates a sub-type of vm_map_ram area, need > > * be set together with VMAP_RAM. > > */ > > WARN_ON(flags == VMAP_BLOCK); > > > > if (!vm && !flags) > > continue; > > > > > > Thanks. If you want you could just ignore the warning. It's a one time > warning so we won't send the mail again and if people have questions > about it, they can just look it up on lore. > > The truth is when I was reviewing this code the first time I got mixed > up between flags and vm->flags so that's part of why I reported it. > > Smatch ignores the WARN_ON(). Historically WARN_ON() has been useless > for indicating whether something can happen or not. These days, > WARN_ON() is treated as a syzkaller bug so we prefer pr_warn() if > something can actually happen. We still see a lot of WARN_ON()s > happening in real life so I'm not eager to make Smatch treat them like a > BUG_ON(). > > Also, sadly, even if we changed the WARN_ON() to a BUG_ON() it still > wouldn't silence the warning because Smatch is not quite clever enough > to parse that. Thanks for your sharing, Dan. My understanding was that our current code alwasys have va->flags with VMAP_RAM when it's set. So the case va->flags == VMAP_BLOCK won't happen. I now understand your worry that it possibly happens. People could change that in the futuer with buggy code or intented action while not noticing that. I may not get your suggestion clearly, wonder if you are suggesting this could be a realtime bug and need be stated in patch log clearly. Thanks Baoquan