Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp329122rdb; Thu, 19 Oct 2023 06:00:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGfMOFJ3jMVEUs/QS/dwje9eGFoQZQ5fsGvsFE0J0L69mIPT/d9KuRXrci0lUNzuohSLKlQ X-Received: by 2002:a05:6870:ebc9:b0:1ea:3f79:defb with SMTP id cr9-20020a056870ebc900b001ea3f79defbmr2510783oab.52.1697720405333; Thu, 19 Oct 2023 06:00:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720405; cv=none; d=google.com; s=arc-20160816; b=GxmGLaL/kr4Sdc/i6QY11UKoCUajvOmyOWKTHoeMuA6wYZAJ1XfFlKnUtg7T5Ny3ay FvXaDdf0hMiTDFUPlXqCRYYN/CKJY7ErlLpfTz+uQr5+Md0k8ZJhcWUKvrMC5qJTA9rL lgAWLMEEZfq9PuKeW66HgMtBPnM6PQz4x2dk2j/pWadds/AVXwRVtrMbzZbhZcRbnu6z q0yQ2KimrrPxCo3xl+WrbkN5Ko1t1XH4/KHxF0AiawBy7SnpDFyhLfvFnkt/3ttOucgl xb0SsLqOi/D4bwLNh+tiiPESOZuTvn5jAFjvb4cH4o2t1IgZ443YySNTuBgs83j3xUpa UbPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=bedN9QfTANJGNML2vYFMLodX6ICVGSptHlSOlZaBF4c=; fh=DoN1NHGr7cnQsPLrR0hVsMWFVfLEhB1izH+2qGuH1Ow=; b=OgjRBkgrYebkk644G6A3C9yXAHOikShZ9kbyS2y1nbQ7y0y1zLHAQA4wLGe5RsyNb1 iF8gSba2OTuTzrNjFAWfks/wm+aJ43ocjisbkKqn4lY/MbrVVioGiZW23boq+LrDHPfX WO8OyF0EuKAfclA6USp07b4gHo5933A/3afhGABJBevaT4l1s1YEe0LazGHfJMbkqF3r G6er8NlIJkJvobGtCA/0UHNHrpXA1vHJRpPis7C+EI43Ph3ZVzwBIsr+3H7rvz1Ofjy7 HP9c+MQI7R/xoRcff6TAznZJdSorLHGOhipSRldaUR2nGots2lkaXLQtcZz1PoiPo8CK bbZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PMRcU6AH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id n6-20020a635906000000b0057d7cff25besi4141714pgb.829.2023.10.19.06.00.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 06:00:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PMRcU6AH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 8A1C2819AD8F; Thu, 19 Oct 2023 05:59:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345780AbjJSM7n (ORCPT + 99 others); Thu, 19 Oct 2023 08:59:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346134AbjJSM67 (ORCPT ); Thu, 19 Oct 2023 08:58:59 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8A982D52 for ; Thu, 19 Oct 2023 05:57:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697720157; 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=PMRcU6AHSW7MOaaV6L8H5gZuGgFjy3MmZYEFma8cwbCX1R0f5/4V3Q70LrvWFNwg68Cg++ arxmnMVKNcs614fy4KR+9VJt1J6xupcVCDCjIxxHvqGUPHU8s0+wyYGxx1s9vgEILNvImk nFgeeGjswHQ+GZZCojbWm0gwiaY9gzc= 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-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:59:59 -0700 (PDT) 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