Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1257044iog; Tue, 14 Jun 2022 02:27:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxnWOiWxGY2hrESSzVvLgqgPyocbZ+/qt46v6O2/pOomvM9ofbLzYXrrruX5AZxFVy/DCh2 X-Received: by 2002:a63:6306:0:b0:3fc:7529:7688 with SMTP id x6-20020a636306000000b003fc75297688mr3815505pgb.252.1655198869420; Tue, 14 Jun 2022 02:27:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655198869; cv=none; d=google.com; s=arc-20160816; b=fDo6wkbrtBHTUMcQST0tUGHykpCxXqTMU4FohRtSQ3b1KCfI+Mn3X4fC7QOfPfYT4B KydFjwPyc7LIKZGFzO7hnDwmpmALLlzZWTbJv8ctl14Iulyyq9tH4AjNpp4kdGpBqoSu Gliq57DxsEQ1CjAQF+/IkeOa0SRLJG71NPsq+WgN3+kZT2XxA7+GlkMEP8XJXhSwRlbf yrHbMuCD9/WjPcNqB+3ul0ncWwrzPgF+zMLeFMpDBdHVJSksOskHxm4wyNWYju74wROY 8LTj6qy8TE4AAMVr4PsRCqFQFThNtxEvHPjrD0Ovm+W9nASKlw1huL+M0SGGjHjEe+dd IYJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=4rkIes9JCll18KoebNY3lMS0ZjcpdgAajPM0Cl2S590=; b=EJcsx3YWpb6MWyn+53tRUxVxjT9Cpi/VMSUg9BV96tOTg1zkRNEIr5plHvbmlxJCMr OtVXZrxa2Md4Y04B+U67v81nvYWnSf1GZYB0HSjzqJznNym5toVTXgI+r0MQFMj2gXPR qcrlFZPSy1AqT+2JanU+d8rXAvry6ydMzXheKqV8R3oGP+/AJ8TULA+/lZPx2udilN3x svDWJrcgJ7132xrMsz46CMgAHDku8lcALOWcSanQspdzhaqrmC6vkkZJpAOmg9PXceTs 2lCjWjn9xy1YniKompiAPyxx6G8hV80kS9IOMMjLgMNP3HK/Uni7J8TdrhHcmjTK+PpR +2wA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kb4-20020a17090ae7c400b001e6820f720esi17859123pjb.125.2022.06.14.02.27.35; Tue, 14 Jun 2022 02:27:49 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239485AbiFNJC3 (ORCPT + 99 others); Tue, 14 Jun 2022 05:02:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242285AbiFNJC0 (ORCPT ); Tue, 14 Jun 2022 05:02:26 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1BF1B868; Tue, 14 Jun 2022 02:02:23 -0700 (PDT) Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4LMj6J4RFLzRj0h; Tue, 14 Jun 2022 16:59:04 +0800 (CST) Received: from ubuntu1804.huawei.com (10.67.174.58) by dggpeml500023.china.huawei.com (7.185.36.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 14 Jun 2022 17:02:01 +0800 From: Xiu Jianfeng To: , , CC: , , Subject: [PATCH -next] apparmor: Fix memleak in aa_simple_write_to_buffer() Date: Tue, 14 Jun 2022 17:00:01 +0800 Message-ID: <20220614090001.155107-1-xiujianfeng@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.174.58] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml500023.china.huawei.com (7.185.36.114) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, 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 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 --- security/apparmor/apparmorfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c index 8b9c92f3ff95..0275a350dc23 100644 --- a/security/apparmor/apparmorfs.c +++ b/security/apparmor/apparmorfs.c @@ -403,7 +403,7 @@ static struct aa_loaddata *aa_simple_write_to_buffer(const char __user *userbuf, data->size = copy_size; if (copy_from_user(data->data, userbuf, copy_size)) { - kvfree(data); + aa_put_loaddata(data); return ERR_PTR(-EFAULT); } -- 2.17.1