From patchwork Mon Feb 10 12:30:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 231704 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=-6.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, 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 E72DDC3B187 for ; Mon, 10 Feb 2020 13:24:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B1EB2208C4 for ; Mon, 10 Feb 2020 13:24:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581341082; bh=0sQasF9IBn8U4b1IBOCJCZMlHvM34h6dAm5fLx7bgWk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=v5dL+UUC5vaEn4NZeY88YAAiu89OhigZcTLSDP+3n6yIm/KF+RDqTcGvQ9pd+n3iK yl4rC1Ai42TrSRUyyJAiMClJUrMroSWOt2rZawyyvysa/P2q0rCxfXIqzYDQiaScNS 5NIGNgUTmCZo70r12TZQ+KGB2Sn7hU1GBo7Yt/Vg= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728905AbgBJNYm (ORCPT ); Mon, 10 Feb 2020 08:24:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:57812 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728606AbgBJMhC (ORCPT ); Mon, 10 Feb 2020 07:37:02 -0500 Received: from localhost (unknown [209.37.97.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 02CCC2080C; Mon, 10 Feb 2020 12:37:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581338222; bh=0sQasF9IBn8U4b1IBOCJCZMlHvM34h6dAm5fLx7bgWk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mWbbzdgZwf06ALDSntQESpPOG4Y2qw9zr7H/cgvKyRbGW6G29RxiqKTjmcKS6B7eT NqqH2K6oF5LLmh9y50RGJ0JZ6CiQX+2/bJW4G88Ue7hqDd8gr6rR6sc1EjZmnF3IfA mUchS/5cDckOz1wIRM/SHFirDZKPCsZwLa1l2wR8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Gustavo A. R. Silva" , Dmitry Vyukov , Andrew Morton , Linus Torvalds Subject: [PATCH 5.4 058/309] lib/test_kasan.c: fix memory leak in kmalloc_oob_krealloc_more() Date: Mon, 10 Feb 2020 04:30:14 -0800 Message-Id: <20200210122411.536891471@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200210122406.106356946@linuxfoundation.org> References: <20200210122406.106356946@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Gustavo A. R. Silva commit 3e21d9a501bf99aee2e5835d7f34d8c823f115b5 upstream. In case memory resources for _ptr2_ were allocated, release them before return. Notice that in case _ptr1_ happens to be NULL, krealloc() behaves exactly like kmalloc(). Addresses-Coverity-ID: 1490594 ("Resource leak") Link: http://lkml.kernel.org/r/20200123160115.GA4202@embeddedor Fixes: 3f15801cdc23 ("lib: add kasan test module") Signed-off-by: Gustavo A. R. Silva Reviewed-by: Dmitry Vyukov Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- lib/test_kasan.c | 1 + 1 file changed, 1 insertion(+) --- a/lib/test_kasan.c +++ b/lib/test_kasan.c @@ -157,6 +157,7 @@ static noinline void __init kmalloc_oob_ if (!ptr1 || !ptr2) { pr_err("Allocation failed\n"); kfree(ptr1); + kfree(ptr2); return; }