From patchwork Mon Mar 29 17:07:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin King X-Patchwork-Id: 12170549 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,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 9B809C433C1 for ; Mon, 29 Mar 2021 17:07:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 238BE6196C for ; Mon, 29 Mar 2021 17:07:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 238BE6196C 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 44A6A6B007B; Mon, 29 Mar 2021 13:07:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F9D16B007E; Mon, 29 Mar 2021 13:07:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2C1B36B0080; Mon, 29 Mar 2021 13:07:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0185.hostedemail.com [216.40.44.185]) by kanga.kvack.org (Postfix) with ESMTP id 0E1776B007B for ; Mon, 29 Mar 2021 13:07:51 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 9D18D12DC for ; Mon, 29 Mar 2021 17:07:50 +0000 (UTC) X-FDA: 77973543900.25.B7ED9B2 Received: from youngberry.canonical.com (youngberry.canonical.com [91.189.89.112]) by imf15.hostedemail.com (Postfix) with ESMTP id DB233A0003A9 for ; Mon, 29 Mar 2021 17:07:36 +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 1lQvMQ-0005B7-AN; Mon, 29 Mar 2021 17:07:30 +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 pointer area after it has been free'd Date: Mon, 29 Mar 2021 18:07:30 +0100 Message-Id: <20210329170730.121943-1-colin.king@canonical.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Stat-Signature: 1dopkju6osby1hxmkmipkci1i71g5cz8 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: DB233A0003A9 Received-SPF: none (canonical.com>: No applicable sender policy available) receiver=imf15; identity=mailfrom; envelope-from=""; helo=youngberry.canonical.com; client-ip=91.189.89.112 X-HE-DKIM-Result: none/none X-HE-Tag: 1617037656-318251 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 Currently the memory pointed to by area is being freed by the free_vm_area call and then area->nr_pages is referencing the free'd object. Fix this swapping the order of the warn_alloc message and the free. Addresses-Coverity: ("Read from pointer after free") Fixes: 014ccf9b888d ("mm/vmalloc: improve allocation failure error messages") Signed-off-by: Colin Ian King Reviewed-by: Uladzislau Rezki (Sony) Signed-off-by: Uladzislau Rezki (Sony) --- mm/vmalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index b73e4e715e0d..7936405749e4 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2790,11 +2790,11 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask, } if (!pages) { - free_vm_area(area); warn_alloc(gfp_mask, NULL, "vmalloc size %lu allocation failure: " "page array size %lu allocation failed", area->nr_pages * PAGE_SIZE, array_size); + free_vm_area(area); return NULL; }