From patchwork Mon Aug 16 17:55:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georgia Garcia X-Patchwork-Id: 1517283 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=TIS+vLZA; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GpMKb2Fprz9sW8; Tue, 17 Aug 2021 03:56:19 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1mFgqO-0002wY-2Y; Mon, 16 Aug 2021 17:56:16 +0000 Received: from smtp-relay-canonical-0.internal ([10.131.114.83] helo=smtp-relay-canonical-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1mFgqI-0002vT-FN for kernel-team@lists.ubuntu.com; Mon, 16 Aug 2021 17:56:10 +0000 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (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 ESMTPS id 4FDD53F10B for ; Mon, 16 Aug 2021 17:56:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1629136570; bh=H8dIEB3LRbm3iYcaTBXsF5OMfg14ogv5reT5Qsjf9TU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TIS+vLZA2xVCZcIFAbKXUB7I7b/nOZj1rKg78Q1vEbZA6zC1Wcq89sMsUbckpiIqC WGbULmuZLPMIOjBGQAjRvU3Uc4ukZvuFoSi8JtUJOZP7W8RVlXq+ZgUBBaMgXPD+j7 Kz4TO7jkZ6ZSWpWIEEqyHRM01VI4+V0QSwL7D9SQrXdKGJ5QtRHWYD4lk122o4MME8 sLXK+T34EJd825UJnq5W0iOf23j81rbNIuTJz30eaHQp9xj8HjbDz8Nt+iH1yPiilx PjcY7rl78VhGDmxDHQy63y8N8BcwE5fhape/TaP/4KRdZrcRbTeicvLAmutm0BX9uh 5Rzyk1ZlZDe8A== Received: by mail-ej1-f69.google.com with SMTP id v19-20020a170906b013b02905b2f1bbf8f3so4953387ejy.6 for ; Mon, 16 Aug 2021 10:56:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=H8dIEB3LRbm3iYcaTBXsF5OMfg14ogv5reT5Qsjf9TU=; b=cGoqA+MHGICeK8cvbSjpo3dCivpdMpXKm4YRxyUg75gzkHeU2ybWKbbSwKk8iX0Dwj MZ9Y/8MsGnOyy+KiEgwY5CRigHDrVaClxWkW4MMOWSDAlJKzs1B17jMxGMqxyvJ4KZjR y3XTR0O0VNP1tUD5PKztqFTTzJak7s6EEW9Lsvk0I4lzlBJJYtqDUu6ihLLuL6RiXMU1 GNxOqEs35/lCLRNDe+g3vApfaVhRnsgaxqsnKPC5oxO4I3rI/IcBo/gp7QFd2njkyqaT TX1/Z21b9azOrTT9zW/fKJW8E1qTRKBloQ8C/bbvrxW+rgVWq41TyYKV8jv+vtdKbwvc YvOA== X-Gm-Message-State: AOAM530TXt2G7BU+dz3Rxjz2aHVFOGntEVLrvIGAnZslNgpDzJysns9p 68AWXg3yB3+sGWgd9/8XtsRAHXTJUjeThXEioi7akIkEJAiybLfuAGQp883eKFMuKKwhxtuq6HL JyyN8DUUrO9vukuAJZ9QKTgiZCTea+hB/ECpSVKNN1g== X-Received: by 2002:a17:906:1fc6:: with SMTP id e6mr16715858ejt.306.1629136569853; Mon, 16 Aug 2021 10:56:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwivSGkxJM7PWdje0llJVIjT8bGE/3+t/5v0Z4Xd+1bcING59casVtT9308FoNzojnEqsP83g== X-Received: by 2002:a17:906:1fc6:: with SMTP id e6mr16715853ejt.306.1629136569695; Mon, 16 Aug 2021 10:56:09 -0700 (PDT) Received: from localhost ([2001:67c:1562:8007::aac:4557]) by smtp.gmail.com with ESMTPSA id q30sm5261453edi.84.2021.08.16.10.56.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 16 Aug 2021 10:56:09 -0700 (PDT) From: Georgia Garcia To: kernel-team@lists.ubuntu.com Subject: [SRU][F][PATCH v3 1/1] apparmor: Fix memory leak of profile proxy Date: Mon, 16 Aug 2021 14:55:57 -0300 Message-Id: <20210816175558.617474-2-georgia.garcia@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210816175558.617474-1-georgia.garcia@canonical.com> References: <20210816175558.617474-1-georgia.garcia@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: John Johansen BugLink: https://bugs.launchpad.net/bugs/1939915 When the proxy isn't replaced and the profile is removed, the proxy is being leaked resulting in a kmemleak check message of unreferenced object 0xffff888077a3a490 (size 16): comm "apparmor_parser", pid 128041, jiffies 4322684109 (age 1097.028s) hex dump (first 16 bytes): 03 00 00 00 00 00 00 00 b0 92 fd 4b 81 88 ff ff ...........K.... backtrace: [<0000000084d5daf2>] aa_alloc_proxy+0x58/0xe0 [<00000000ecc0e21a>] aa_alloc_profile+0x159/0x1a0 [<000000004cc9ce15>] unpack_profile+0x275/0x1c40 [<000000007332b3ca>] aa_unpack+0x1e7/0x7e0 [<00000000e25e31bd>] aa_replace_profiles+0x18a/0x1d10 [<00000000350d9415>] policy_update+0x237/0x650 [<000000003fbf934e>] profile_load+0x122/0x160 [<0000000047f7b781>] vfs_write+0x139/0x290 [<000000008ad12358>] ksys_write+0xcd/0x170 [<000000001a9daa7b>] do_syscall_64+0x70/0x310 [<00000000b9efb0cf>] entry_SYSCALL_64_after_hwframe+0x49/0xb3 Make sure to cleanup the profile's embedded label which will result on the proxy being properly freed. Fixes: 637f688dc3dc ("apparmor: switch from profiles to using labels on contexts") Signed-off-by: John Johansen (cherry picked from commit 3622ad25d4d68fcbdef3bc084b5916873e785344) Signed-off-by: Georgia Garcia --- security/apparmor/include/label.h | 1 + security/apparmor/label.c | 13 +++++++------ security/apparmor/policy.c | 1 + 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/security/apparmor/include/label.h b/security/apparmor/include/label.h index b1aeb282ca22..9cd61eaa630e 100644 --- a/security/apparmor/include/label.h +++ b/security/apparmor/include/label.h @@ -275,6 +275,7 @@ void aa_labelset_destroy(struct aa_labelset *ls); void aa_labelset_init(struct aa_labelset *ls); void __aa_labelset_update_subtree(struct aa_ns *ns); +void aa_label_destroy(struct aa_label *label); void aa_label_free(struct aa_label *label); void aa_label_kref(struct kref *kref); bool aa_label_init(struct aa_label *label, int size); diff --git a/security/apparmor/label.c b/security/apparmor/label.c index de3b83f5377b..0afe670742e8 100644 --- a/security/apparmor/label.c +++ b/security/apparmor/label.c @@ -309,7 +309,7 @@ int aa_vec_unique(struct aa_profile **vec, int n, int flags) } -static void label_destroy(struct aa_label *label) +void aa_label_destroy(struct aa_label *label) { AA_BUG(!label); @@ -326,12 +326,13 @@ static void label_destroy(struct aa_label *label) } } - if (rcu_dereference_protected(label->proxy->label, true) == label) - rcu_assign_pointer(label->proxy->label, NULL); - + if (label->proxy) { + if (rcu_dereference_protected(label->proxy->label, true) == label) + rcu_assign_pointer(label->proxy->label, NULL); + aa_put_proxy(label->proxy); + } aa_free_secid(label->secid); - aa_put_proxy(label->proxy); label->proxy = (struct aa_proxy *) PROXY_POISON + 1; } @@ -340,7 +341,7 @@ void aa_label_free(struct aa_label *label) if (!label) return; - label_destroy(label); + aa_label_destroy(label); kfree(label); } diff --git a/security/apparmor/policy.c b/security/apparmor/policy.c index 0e9f8e5bae62..eb7ba4d3df41 100644 --- a/security/apparmor/policy.c +++ b/security/apparmor/policy.c @@ -240,6 +240,7 @@ void aa_free_profile(struct aa_profile *profile) kzfree(profile->hash); aa_put_loaddata(profile->rawdata); + aa_label_destroy(&profile->label); kzfree(profile); }