Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp901855rwe; Wed, 24 Aug 2022 10:56:31 -0700 (PDT) X-Google-Smtp-Source: AA6agR4BBsdv9jpNCFf1wP3LNQTd08WE2a9z3WujybABVPJUjnZUJuiLVP7N8YUMKdNgpdfxeZDT X-Received: by 2002:a05:6402:248d:b0:437:dd4c:e70e with SMTP id q13-20020a056402248d00b00437dd4ce70emr153634eda.75.1661363791331; Wed, 24 Aug 2022 10:56:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661363791; cv=none; d=google.com; s=arc-20160816; b=QOZN1VzBTzyf+IcKLP5p8h5k3moGubX6kjRH6UP+L7caMEN0JkISM2B8XoBnh6AJl9 x3qs7JcOjFp7sEgo2IZUlQGq/uYAYVIvx70Egqg3+N/DtfJJuinzYBOKWETkvhKoy4rW qQBerru45kbSeDAv/hxGm4rPAsXWbVkg/EVFxLtkobEqoV0fu18DfS1eLdt/tEpskDM2 N9gFAjy082gFQV8IsG9o/srKAqBIXSTKzPXfgi3r6PhNU5r2y929De71e0i7mn5TQwTD ks2W41p2GI/aDr/56dbmYjxs/W8iOJWQYWLfRimODAk/N0V9lVIE1QM2Xqg3Xl2OXNk8 dy6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=tUvu8igyJ8SieKzyGBjoH9CdpCFj5M06wi08ejJhQtk=; b=SFnRpg7Q47Q1PEjGmif3VmiF/19MUyUoZvFLFWcWuuSk5nLBdBquwRGh8XsDkBZDzW HwRmTTH37rX2bEySjXvQDR4uWjpecBv4rPfqIZj3rCH7LmgbRXe7CgBWm+RXdrSoax/I suWxShLOqjQM9xom0wxHfSP54ZEurcrwgf7Iy3cY0vVmGl81PeJarspyha5mWdj3tdos HwZTOXHP0/JCoNaiaWr16fzordglgftsvSbcwGMMjy6Ha7zUgxy+ObtC6tC7QKqTbbRl EJF0eYKSeUQxcerTEEtiQhcUn92uxne05tZK22fYDoBRA5peyqTdAODsF9GfvNhfE5V8 ZwpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=Xts7Tuur; 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=canonical.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p10-20020a50c94a000000b0043c94d7ddb8si4146249edh.204.2022.08.24.10.56.05; Wed, 24 Aug 2022 10:56:31 -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=@canonical.com header.s=20210705 header.b=Xts7Tuur; 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=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239861AbiHXRKQ (ORCPT + 99 others); Wed, 24 Aug 2022 13:10:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238311AbiHXRKM (ORCPT ); Wed, 24 Aug 2022 13:10:12 -0400 Received: from smtp-relay-canonical-0.canonical.com (smtp-relay-canonical-0.canonical.com [185.125.188.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9D49481FD; Wed, 24 Aug 2022 10:10:10 -0700 (PDT) Received: from [10.0.0.100] (cpe5896308f56e8-cm5896308f56e6.cpe.net.cable.rogers.com [99.255.30.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id 3B56D3F04B; Wed, 24 Aug 2022 17:10:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1661361008; bh=tUvu8igyJ8SieKzyGBjoH9CdpCFj5M06wi08ejJhQtk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Xts7TuuryXoFLDS4GpHrw+LeRz7edXUpX+4dYUmPobUcQ+KJnICV0WlWUTmfjg9Pd MPi0RNfOYAe9QXzE7eWT8pWjLNW2JuMRFcTTbmUt02DzbBGfl8KRVjxVP8ObSYvfNx gsoBsXaGvoQF/Yk9yMYP4e2PZIrBd2ZCzR/PygfjgVWI5+zs8z7KEwhsCXD3h/zyFl pvEdmX3t7jtBKYPGreXYoYX4bOwL12J/44sU7tv5ToeYLWw3DbuTRv6NC0aYrcOnT6 ppDSZuE6169ipImQTGbppm1g6TVf+1boo+4Wp5sUPK/kgO/AEqTQG3q+Yhlu2WfHp/ CiZVqqkCaUTiw== Message-ID: <90e259e4-6877-ee1e-ed6e-aa972f305126@canonical.com> Date: Wed, 24 Aug 2022 10:10:05 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH] apparmor: fix a memleak in multi_transaction_new() Content-Language: en-US To: Gaosheng Cui , paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com Cc: apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org References: <20220823011503.2757088-1-cuigaosheng1@huawei.com> From: John Johansen Organization: Canonical In-Reply-To: <20220823011503.2757088-1-cuigaosheng1@huawei.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED 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 On 8/22/22 18:15, Gaosheng Cui wrote: > In multi_transaction_new(), the variable t is not freed or passed out > on the failure of copy_from_user(t->data, buf, size), which could lead > to a memleak. > > Fix this bug by adding a put_multi_transaction(t) in the error path. > > Fixes: 1dea3b41e84c5 ("apparmor: speed up transactional queries") > Signed-off-by: Gaosheng Cui yep, thanks. I will pull this into apparmor-next Acked-by: John Johansen > --- > security/apparmor/apparmorfs.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c > index d066ccc219e2..7160e7aa58b9 100644 > --- a/security/apparmor/apparmorfs.c > +++ b/security/apparmor/apparmorfs.c > @@ -868,8 +868,10 @@ static struct multi_transaction *multi_transaction_new(struct file *file, > if (!t) > return ERR_PTR(-ENOMEM); > kref_init(&t->count); > - if (copy_from_user(t->data, buf, size)) > + if (copy_from_user(t->data, buf, size)) { > + put_multi_transaction(t); > return ERR_PTR(-EFAULT); > + } > > return t; > }