From patchwork Thu Mar 18 15:59:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin King X-Patchwork-Id: 12148471 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 1AA7DC433E6 for ; Thu, 18 Mar 2021 16:00:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 945EE64E6B for ; Thu, 18 Mar 2021 16:00:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 945EE64E6B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=canonical.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1698B6B0072; Thu, 18 Mar 2021 12:00:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 13EF18D0001; Thu, 18 Mar 2021 12:00:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 02D1D6B0074; Thu, 18 Mar 2021 12:00:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0040.hostedemail.com [216.40.44.40]) by kanga.kvack.org (Postfix) with ESMTP id DC45E6B0072 for ; Thu, 18 Mar 2021 12:00:03 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 96DD18249980 for ; Thu, 18 Mar 2021 16:00:03 +0000 (UTC) X-FDA: 77933456286.16.7B85723 Received: from youngberry.canonical.com (youngberry.canonical.com [91.189.89.112]) by imf28.hostedemail.com (Postfix) with ESMTP id 3A06B200038A for ; Thu, 18 Mar 2021 16:00:00 +0000 (UTC) Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1lMv3z-0004rh-J8; Thu, 18 Mar 2021 15:59:55 +0000 From: Colin King To: Andrew Morton , Stephen Rothwell , Nicholas Piggin , linux-mm@kvack.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next] mm/vmalloc: fix read of uninitialized pointer area Date: Thu, 18 Mar 2021 15:59:55 +0000 Message-Id: <20210318155955.18220-1-colin.king@canonical.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Stat-Signature: ge39fjw9zmga6eonin49zz9ku6homftp X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 3A06B200038A Received-SPF: none (canonical.com>: No applicable sender policy available) receiver=imf28; identity=mailfrom; envelope-from=""; helo=youngberry.canonical.com; client-ip=91.189.89.112 X-HE-DKIM-Result: none/none X-HE-Tag: 1616083200-813701 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: From: Colin Ian King 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: 1. var_decl: Declaring variable area without initializer. struct vm_struct *area; ... 2. Condition !size, taking true branch. if (!size || (size >> PAGE_SHIFT) > totalram_pages()) 3. Jumping to label fail. goto fail; ... 4. Condition shift > 12, taking false branch. fail: if (shift > PAGE_SHIFT) { shift = PAGE_SHIFT; align = real_align; size = real_size; goto again; } Uninitialized pointer read (UNINIT) 5. uninit_use: Using uninitialized value area. if (!area) { ... } Fix this by setting area to NULL to avoid the uninitialized read of area. Addresses-Coverity: ("Uninitialized pointer read") Fixes: 92db9fec381b ("mm/vmalloc: hugepage vmalloc mappings") Signed-off-by: Colin Ian King Acked-by: Nicholas Piggin --- mm/vmalloc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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, unsigned long align, unsigned long real_align = align; unsigned int shift = PAGE_SHIFT; - if (!size || (size >> PAGE_SHIFT) > totalram_pages()) + if (!size || (size >> PAGE_SHIFT) > totalram_pages()) { + area = NULL; goto fail; + } if (vmap_allow_huge && !(vm_flags & VM_NO_HUGE_VMAP) && arch_vmap_pmd_supported(prot)) {