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=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 87EEAC433C1 for ; Mon, 22 Mar 2021 02:46:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 02EC661878 for ; Mon, 22 Mar 2021 02:46:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 02EC661878 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4297E6B0036; Sun, 21 Mar 2021 22:27:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3DD9D6B006C; Sun, 21 Mar 2021 22:27:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1E7206B0070; Sun, 21 Mar 2021 22:27:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0236.hostedemail.com [216.40.44.236]) by kanga.kvack.org (Postfix) with ESMTP id EE7346B0036 for ; Sun, 21 Mar 2021 22:27:57 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 4B4508249980 for ; Mon, 22 Mar 2021 02:46:48 +0000 (UTC) X-FDA: 77945972496.27.9ED1458 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by imf07.hostedemail.com (Postfix) with ESMTP id DABCAA0009CE for ; Mon, 22 Mar 2021 02:46:47 +0000 (UTC) Received: by mail-pf1-f182.google.com with SMTP id l123so9973555pfl.8 for ; Sun, 21 Mar 2021 19:46:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:subject:to:cc:references:in-reply-to:mime-version :message-id:content-transfer-encoding; bh=ROrvaACa9JFo5JYfkhQ5xT+HNviJr75NpvRYSiGrQY0=; b=CdIc2p6wl8pgrq+L9C/WOp5shBZ8eAYIj5Su6jyrnILApkbqSZh8lpsa7SobD5t4nJ WjtoobZXECzRcztRxpG2oKrwLev2/pS692wdjrbY+ljuaulIg0wDgiLNO2mmmi++WpIu B2stIGEKNSvkBjeC7H3prZu48UxuQ26URpeAXSqrbhn2lu0OTaQETGN5+DFeHWRA4BCY iNewr+pCJUckhfCAdNxSQShvGMjhaxbE8CUUBpYOWJgrZX7aAy8wRx5OIaNby38cSG6y HPfwsAznYMJP172P2uyyLKPbfC3MHBmDBXeXuHXy/T8v1Tn40rfjm873wsVbX2aHsqU7 lLeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:subject:to:cc:references:in-reply-to :mime-version:message-id:content-transfer-encoding; bh=ROrvaACa9JFo5JYfkhQ5xT+HNviJr75NpvRYSiGrQY0=; b=pgPAjArQdutqF/qo6dDbpiJDh+FqiUknd5+TQcnM9enP/PTJ8Z5Z4rliu78KAWZG1d sKTqwRsbtxyMamFP34kXHmIMQ6c59GaLBQMyzufd1tH0sBjXipBVlnJ+F2AsM9/vbNRx Awl+Qzm0kY5W9CKpKLIR2iGR0l4eJLgDGViiUqejCDp0eFph8HF+1qvAXJV0t41PJd4f EhFzRmzNgxdkYTJL8r88erk4+tnJvCPWRUyLfGJdkBB9SS7jVrw5rcScKe9wv3n4jPEJ 8KOoBWCQmUAMnR1O8aiO48ufD3vzJBYkb+S1OVPddhChEFwBCck4S7u33w413PTmv7Oh 3gCQ== X-Gm-Message-State: AOAM530LMYZBJFyHR7Tr2GfxKKySju4ktRtiJRMhurbSxvWNHV3IO0Eq LLS4Uv7A2py6TpWHF+7BfV8= X-Google-Smtp-Source: ABdhPJwfFsd694+wMyX4mbtZFeSavL4b/+VWKM8IKCcOqj8Yr8G9hzvBwLqJaLUJTUrK60NqlM50Og== X-Received: by 2002:a05:6a00:a95:b029:1ee:471f:e323 with SMTP id b21-20020a056a000a95b02901ee471fe323mr18880496pfl.69.1616381206887; Sun, 21 Mar 2021 19:46:46 -0700 (PDT) Received: from localhost ([58.84.78.96]) by smtp.gmail.com with ESMTPSA id v27sm11703351pfi.89.2021.03.21.19.46.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 19:46:46 -0700 (PDT) Date: Mon, 22 Mar 2021 12:46:40 +1000 From: Nicholas Piggin Subject: Re: [PATCH][next] mm/vmalloc: fix read of uninitialized pointer area To: Andrew Morton , Colin King , linux-mm@kvack.org, Stephen Rothwell Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org References: <20210318155955.18220-1-colin.king@canonical.com> In-Reply-To: <20210318155955.18220-1-colin.king@canonical.com> MIME-Version: 1.0 Message-Id: <1616381157.eirpjq5f8p.astroid@bobo.none> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Stat-Signature: 8o66e47tk1kgdwjxpo5bzdpnhtbf8675 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: DABCAA0009CE Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf07; identity=mailfrom; envelope-from=""; helo=mail-pf1-f182.google.com; client-ip=209.85.210.182 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616381207-524276 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: Excerpts from Colin King's message of March 19, 2021 1:59 am: > From: Colin Ian King >=20 > There is a corner case where the sanity check of variable size fails > and branches to label fail and shift can be less than PAGE_SHIFT > causing area to never be assigned. This was picked up by static > analysis as follows: >=20 > 1. var_decl: Declaring variable area without initializer. > struct vm_struct *area; >=20 > ... >=20 > 2. Condition !size, taking true branch. > if (!size || (size >> PAGE_SHIFT) > totalram_pages()) > 3. Jumping to label fail. > goto fail; >=20 > ... >=20 > 4. Condition shift > 12, taking false branch. > fail: > if (shift > PAGE_SHIFT) { > shift =3D PAGE_SHIFT; > align =3D real_align; > size =3D real_size; > goto again; > } >=20 > Uninitialized pointer read (UNINIT) > 5. uninit_use: Using uninitialized value area. > if (!area) { > ... > } >=20 > Fix this by setting area to NULL to avoid the uninitialized read > of area. >=20 > Addresses-Coverity: ("Uninitialized pointer read") > Fixes: 92db9fec381b ("mm/vmalloc: hugepage vmalloc mappings") > Signed-off-by: Colin Ian King Looks good to me. Acked-by: Nicholas Piggin Thanks, Nick > --- > mm/vmalloc.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) >=20 > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > index 96444d64129a..4b415b4bb7ae 100644 > --- a/mm/vmalloc.c > +++ b/mm/vmalloc.c > @@ -2888,8 +2888,10 @@ void *__vmalloc_node_range(unsigned long size, uns= igned long align, > unsigned long real_align =3D align; > unsigned int shift =3D PAGE_SHIFT; > =20 > - if (!size || (size >> PAGE_SHIFT) > totalram_pages()) > + if (!size || (size >> PAGE_SHIFT) > totalram_pages()) { > + area =3D NULL; > goto fail; > + } > =20 > if (vmap_allow_huge && !(vm_flags & VM_NO_HUGE_VMAP) && > arch_vmap_pmd_supported(prot)) { > --=20 > 2.30.2 >=20 >=20