Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp79709rdb; Wed, 18 Oct 2023 19:29:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE0PXdlx3OR/1d5hVwE6eNKdPTJXC/bgg/7FaBhtp7Up7SMdR3fypDV+LvNK9IFws5ifxsq X-Received: by 2002:a9d:74d9:0:b0:6b9:dc90:8a85 with SMTP id a25-20020a9d74d9000000b006b9dc908a85mr1046811otl.24.1697682583268; Wed, 18 Oct 2023 19:29:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697682583; cv=none; d=google.com; s=arc-20160816; b=JjMaPd6zwTtWvQohA1+Ij/FKrvKoe1/zgp3D5KoT9eLbFV1UldNCm0Q3rF3higtqYC tPoAOuDaRrRV45Kr1+hfL13GBnICJf15OE72L6JlQ8yQMI+tPZd+pwirvulugngjEnNc RzrUyp2Aw+HeqKAgMOhNUjrgM3Eu83ghVcVUR9K2BP2OwsLeeUP/P+OzjPdm4H41tzXA JJXtY3XifWBBtsFh/GtdljT31oqgYonTaoWSwAx/htCWq9B1JfD9uSIiaOjIMgLec5ZG ptgD38Q71OEf1tqITHfFUwp3+c4IEd/pEVc256l8efVTWWisO2ME6t0rID0UGnjj+qtS UVQQ== 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=U3e/R8h8CUl6Qt8HzoNg568ab2TdGmvLJ3uBUWajvX8=; fh=lQPz00wFSeO4G89aMX+/uChzF40oY3Jruae+kFOSbsU=; b=Jq5+F0FOmrWBbcR9E6lbE7aU6LiWK6QmhaCiwnVPxVAfvzv16milkTyQpvBll/HKM2 BljTMDZeEq5qacrs1uv/VsO1pNnZvZPxhijAyB1AnJC6Rl5SE2ABWA1385swF2rFW78H H+fy7QUGhNB8XzjCwu7F6VGWRVi/haCYFci1E8T2lr0qzb8wsXw+9TT4Du5Svgud8g++ MKiMwdqHFyH/lRaC0FiREXlZxGo7fyFYtF7ipU5mIoPz5EgV48RdGfD2qpP3EKC7Stpb f08FbUIKL40mWZNL3fzqMsUA/V2XORj/mh8xNMj39so0VGOyq1bzrQPGVvEodfxRcYlj +QaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QwItNz3R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id t4-20020a63f344000000b005859c29ce86si3157218pgj.84.2023.10.18.19.29.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 19:29:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QwItNz3R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id D2AF78228991; Wed, 18 Oct 2023 19:29:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232332AbjJSC3V (ORCPT + 99 others); Wed, 18 Oct 2023 22:29:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229632AbjJSC3T (ORCPT ); Wed, 18 Oct 2023 22:29:19 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AF3F115 for ; Wed, 18 Oct 2023 19:28:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697682512; 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=U3e/R8h8CUl6Qt8HzoNg568ab2TdGmvLJ3uBUWajvX8=; b=QwItNz3RakzvaWt1AwSLGsq6K37izQx3CHpNro2xoBj/LrlAzOrI9gcShmVrfOVydKc/ff CC0fQuOoroFxvLyI3MpsEyhRUsJeLM+vb9D4odKfj8A5ef+9XUSvYnR4pn0tCIPQ54nfWK desrPpuAXhhi0S/Y3f5cfc8dtzkZPLc= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-544-Xqo4N_V8NMSwLG0l_9noLA-1; Wed, 18 Oct 2023 22:28:27 -0400 X-MC-Unique: Xqo4N_V8NMSwLG0l_9noLA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 7FC7D29AA383; Thu, 19 Oct 2023 02:28:26 +0000 (UTC) Received: from localhost (unknown [10.72.112.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B79DB503B; Thu, 19 Oct 2023 02:28:25 +0000 (UTC) Date: Thu, 19 Oct 2023 10:28:21 +0800 From: Baoquan He To: Andrew Morton Cc: Dan Carpenter , 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231018085248.6f3f36101cbdfe0990c8b467@linux-foundation.org> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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 howler.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 (howler.vger.email [0.0.0.0]); Wed, 18 Oct 2023 19:29:38 -0700 (PDT) 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; From 89cc02302766ab7a67cc668390c24079b4a9406b Mon Sep 17 00:00:00 2001 From: Baoquan He Date: Wed, 18 Oct 2023 22:50:14 +0800 Subject: [PATCH v2] 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 ===================== This is not a real-time bug because the possible null 'vm' in the pointed place could only happen when flags == VMAP_BLOCK. However, the case 'flags == VMAP_BLOCK' should never happen and has been detected with WARN_ON. Please check vm_map_ram() implementation and the earlier checking in vread_iter() at below: ~~~~~~~~~~~~~~~~~~~~~~~~~~ /* * 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; ~~~~~~~~~~~~~~~~~~~~~~~~~~ So add checking on whether 'vm' could be 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 --- v1->v2: - Update patch log to state that it's not a realtime bug as Andrew suggested. 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