From patchwork Thu Feb 1 14:24:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fedor Pchelkin X-Patchwork-Id: 195352 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2719:b0:106:209c:c626 with SMTP id hl25csp188675dyb; Thu, 1 Feb 2024 06:26:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IE5qqnN/KUxrtU6aHOCrCOTXUXd4Ccvo3luRn2JsUJtG0/gYvYfBAPh73Rz1RvHs3s1Go+V X-Received: by 2002:a17:906:b283:b0:a36:55e8:ea40 with SMTP id q3-20020a170906b28300b00a3655e8ea40mr1730593ejz.41.1706797566948; Thu, 01 Feb 2024 06:26:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706797566; cv=pass; d=google.com; s=arc-20160816; b=VPmdgTvc4Ki6wzRidnyF4TnTSYnjpI6mE0EuPKOywDlWrYYGa4LC9grSet2/T50DoJ 64+5BylCBkpGXiPjCjcPs1WWdRVkq9oMV42GoKZeicACTceOG+DuApzCC9mgQNy61hdu KBGqG++5FQAMARpHGv0wuoiJNzJ+GTBFHeQkwPb0mEtes2uyv4OwwGT6T9ZqbVVeMVA3 tmVqL0GasWKbgY5bbTZVCvn6k2MvuEhA7LqWNEktVFszfO/FewMhJs2aECW0Zr8dbnZ4 s7M3LZhQT7sE+RkGiQXxYKwrsvJGa+uuzH4ANJJpFygbkUActXRLAvCa+Ba4glDP6A6e 2ucA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature:dkim-filter; bh=EfXwutwttYNswqPhr1DI1HL9a39mqxWde2M9ylas6wE=; fh=Uq7b95ilPzbGCFeUwjn01BfejJ2N6yQHdgYPiQKJFqE=; b=eT9XlRrZcJIa9yQt1L3aBxmFVyWF0pVkAJUBdAPxIbpWIxw/iQWUbxYe75eoQhKJt+ 9kdF5ax5eiQInPrnzpA0rwfy5Br85ykrt5HPxs367o9G5AA+zGemvRrXZLBo6OWZdCoc f85cpDUQzUFZboyRkHaRewaG0kG8aaUmXvR3+/Q1Hf70C8Nnyb2yZ0VbXAWJYyD6p15D Vr5FbV9kLPMSA3Z9V5rTMRFp0rbWoDx9eW9xwbxeQTw4UYePyiB+gLpAStBcsf4SAHWE Rjxgv2CIZbod6oT9eeA2UuMKBHRHCLT0VpCrLALAT6yXtk2WXNQlCDDgANhSJdcQBgbK q06g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=Y12xKooR; arc=pass (i=1 spf=pass spfdomain=ispras.ru dkim=pass dkdomain=ispras.ru dmarc=pass fromdomain=ispras.ru); spf=pass (google.com: domain of linux-kernel+bounces-48318-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48318-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru X-Forwarded-Encrypted: i=1; AJvYcCUVGthlN8rFIDXYm+4RJINPgRudgYt89b5pn1i9FukfzZD9t7DKitnkR/lodqKOMZrYxVpgyc0O/0RBEAk5nyJgmLEzUg== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id y17-20020a1709060a9100b00a31885d70c0si6406590ejf.427.2024.02.01.06.26.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 06:26:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48318-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=Y12xKooR; arc=pass (i=1 spf=pass spfdomain=ispras.ru dkim=pass dkdomain=ispras.ru dmarc=pass fromdomain=ispras.ru); spf=pass (google.com: domain of linux-kernel+bounces-48318-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48318-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 8EF2D1F2A066 for ; Thu, 1 Feb 2024 14:26:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2FEA65F494; Thu, 1 Feb 2024 14:25:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ispras.ru header.i=@ispras.ru header.b="Y12xKooR" Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E35C5B69B; Thu, 1 Feb 2024 14:25:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=83.149.199.84 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706797537; cv=none; b=qGMtbYcuLbX6sd0qlD4tprmyXg6UUr94e6uaxdECILVr5gHDtwAl+PYWY8h9zufcheVSDwmsHvSE7vdqstEsUldRladlvhv9cX3YEznAFvoqE40atoO2M0x1jcxckayehTYyEL1bhrVPH1TzD3z6Up1lS/rBBCDiwXvjKnXkAtk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706797537; c=relaxed/simple; bh=sF+G8ac5rJ6GBWZ7UGnOBa+TCEI+k8Sh7jK8bcRdt4A=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=lr24SnGcDCo2tBCZ2DuD+TUIcT1xLMgyl4oLwGnEq4kvk+hudFBthSHzV6Oq30qKbU+U4LtrbqL3BF+5evF8LzACDb+0KynhAgyGdDYE/imwfA6KcOb31D7udZKIF0nNVYeK9kIhlBWRV/6uMNBMXNWmR7YdG4G+kuFLXYnqej8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ispras.ru; spf=pass smtp.mailfrom=ispras.ru; dkim=pass (1024-bit key) header.d=ispras.ru header.i=@ispras.ru header.b=Y12xKooR; arc=none smtp.client-ip=83.149.199.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ispras.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ispras.ru Received: from localhost.localdomain (unknown [46.242.8.170]) by mail.ispras.ru (Postfix) with ESMTPSA id A966D40737B5; Thu, 1 Feb 2024 14:25:23 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru A966D40737B5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1706797524; bh=EfXwutwttYNswqPhr1DI1HL9a39mqxWde2M9ylas6wE=; h=From:To:Cc:Subject:Date:From; b=Y12xKooRC1gohuym47VGPE7BZOR5fJOk4yOt3snNMmweJ0+EwkyTkgaBaAM0zbVUo rLyykzqzbSrlb1JoW8+DDaVSYeUbNS4SNvfleXDxv2muqqTC7dVUMG7kTMChJqX1ox 8GUdYYj5E4KwthHbuLZW0+lOAcl2V95PFhXRu+Ko= From: Fedor Pchelkin To: John Johansen Cc: Fedor Pchelkin , Paul Moore , James Morris , "Serge E. Hallyn" , William Hua , apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org, Alexey Khoroshilov , stable@vger.kernel.org Subject: [PATCH] apparmor: use kvfree_sensitive to free data->data Date: Thu, 1 Feb 2024 17:24:48 +0300 Message-ID: <20240201142450.30510-1-pchelkin@ispras.ru> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789706965054133112 X-GMAIL-MSGID: 1789706965054133112 Inside unpack_profile() data->data is allocated using kvmemdup() so it should be freed with the corresponding kvfree_sensitive(). Also add missing data->data release for rhashtable insertion failure path in unpack_profile(). Found by Linux Verification Center (linuxtesting.org). Fixes: e025be0f26d5 ("apparmor: support querying extended trusted helper extra data") Cc: stable@vger.kernel.org Signed-off-by: Fedor Pchelkin --- security/apparmor/policy.c | 2 +- security/apparmor/policy_unpack.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/security/apparmor/policy.c b/security/apparmor/policy.c index 957654d253dd..14df15e35695 100644 --- a/security/apparmor/policy.c +++ b/security/apparmor/policy.c @@ -225,7 +225,7 @@ static void aa_free_data(void *ptr, void *arg) { struct aa_data *data = ptr; - kfree_sensitive(data->data); + kvfree_sensitive(data->data, data->size); kfree_sensitive(data->key); kfree_sensitive(data); } diff --git a/security/apparmor/policy_unpack.c b/security/apparmor/policy_unpack.c index 5e578ef0ddff..75452acd0e35 100644 --- a/security/apparmor/policy_unpack.c +++ b/security/apparmor/policy_unpack.c @@ -1071,6 +1071,7 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name) if (rhashtable_insert_fast(profile->data, &data->head, profile->data->p)) { + kvfree_sensitive(data->data, data->size); kfree_sensitive(data->key); kfree_sensitive(data); info = "failed to insert data to table";