Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3469409rwa; Tue, 23 Aug 2022 05:24:03 -0700 (PDT) X-Google-Smtp-Source: AA6agR64Oahy+QLgGd5sPW/vkefrus2FubuUdvjgnAb1NzzCUFId60TgeLE9uqoQetkhNLr8he3r X-Received: by 2002:a17:903:22d1:b0:172:f11f:de35 with SMTP id y17-20020a17090322d100b00172f11fde35mr7188957plg.150.1661257442900; Tue, 23 Aug 2022 05:24:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661257442; cv=none; d=google.com; s=arc-20160816; b=zpZTHPKlI9ABIRyBXzwv/w6637SlzGX54/Iwm3zadw6a95YCwk/RcNj9y2ARWgjx09 bBZSlhCEwxvkomTsHr5mDjrAzRkvIX5fxTFlDvoART/E/rIebF66EsK9gKuEVZkzM2/4 RM0YdmszNMP/FHeFQeHUeHlnf4Nyvtx2cAJ84iZvZb4fsmsJ1u5d6Ky8fFpiYydVB97L tMUuy9X6fET6iGUm+gWMfHkcnEW7hVPkV8JaDleKa6IVlzn5bKrXoXuf/25Dhbq3SWMa ec61bVFmFt/wel13Ifx5hDhLu8MfP0kK+aS99oqeecaCaXR/BqLNn5H8EmXI8vuOkuwg bL1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cLwZqYGtoI8EpSOv5cR7RA7j2at2kptHJUKSwtIrtyY=; b=sNrfEebwkxFl6UNRwpOwooCKcEPP1lBJrsuCZjPcwD+h4P+OXfJhgDp/VqXuNnO18h GpM4UWQM3zglPUWJo7HlX8AyB58S3zETral5EcbRSPzAQTZMFrJHQRZS1d0ffWYP8zPW TvxxxUMKveU2ENeb100vx+UIIzZ9H4gW/b0Ahtw0wCOoF/TQvTlteK/hs6XXvBrFMg3E MoxbBefTNFFjXmPTyjFEJKIyvgu28eDrQ2yy5c+BpN5z3TOUxB3uJpstLK0F9N7TdS9/ e/mzn0JbAcbb1mSixAUCcnbxxiZOFX28hFbIMnocXRlC2iG5GsH+mSdISmThvcg88lQf bq8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Zxy++z+J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c1-20020a170902aa4100b00172a54835b7si12741250plr.612.2022.08.23.05.23.52; Tue, 23 Aug 2022 05:24:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Zxy++z+J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356750AbiHWKys (ORCPT + 99 others); Tue, 23 Aug 2022 06:54:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348712AbiHWKrg (ORCPT ); Tue, 23 Aug 2022 06:47:36 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FE0E86B60; Tue, 23 Aug 2022 02:11:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EB62E60F50; Tue, 23 Aug 2022 09:11:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E7FD2C433D7; Tue, 23 Aug 2022 09:11:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661245913; bh=2xyhPch0MJygp7RYrx8cqb8RHV1ck2BsROSzHKc8JQ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zxy++z+J7gmG1jE1aSKeCFO+QSaKYPreuBDGTocRw6Zs+QzHOSLUkpArb1yyD3IKs LPO8jE5PZ4VbUrJJPXXjU+MJv3NLJdkPOKZpNuY5Ks7VFGglbiLWB0n27VRWz/PAxI EchE5gK2Z/MTVcDTCJ0hnQKLjQU2jDK5YKIFrzN8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiu Jianfeng , John Johansen Subject: [PATCH 4.19 229/287] apparmor: Fix memleak in aa_simple_write_to_buffer() Date: Tue, 23 Aug 2022 10:26:38 +0200 Message-Id: <20220823080108.728228207@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080100.268827165@linuxfoundation.org> References: <20220823080100.268827165@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xiu Jianfeng commit 417ea9fe972d2654a268ad66e89c8fcae67017c3 upstream. When copy_from_user failed, the memory is freed by kvfree. however the management struct and data blob are allocated independently, so only kvfree(data) cause a memleak issue here. Use aa_put_loaddata(data) to fix this issue. Fixes: a6a52579e52b5 ("apparmor: split load data into management struct and data blob") Signed-off-by: Xiu Jianfeng Signed-off-by: John Johansen Signed-off-by: Greg Kroah-Hartman --- security/apparmor/apparmorfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/security/apparmor/apparmorfs.c +++ b/security/apparmor/apparmorfs.c @@ -403,7 +403,7 @@ static struct aa_loaddata *aa_simple_wri data->size = copy_size; if (copy_from_user(data->data, userbuf, copy_size)) { - kvfree(data); + aa_put_loaddata(data); return ERR_PTR(-EFAULT); }