From patchwork Fri Aug 13 19:08:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georgia Garcia X-Patchwork-Id: 1516747 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=WrXGry4J; 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 4GmY4j483zz9sW8; Sat, 14 Aug 2021 05:08:53 +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 1mEcXx-0000u3-7H; Fri, 13 Aug 2021 19:08:49 +0000 Received: from smtp-relay-canonical-1.internal ([10.131.114.174] helo=smtp-relay-canonical-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1mEcXr-0000sh-BK for kernel-team@lists.ubuntu.com; Fri, 13 Aug 2021 19:08:43 +0000 Received: from mail-ot1-f70.google.com (mail-ot1-f70.google.com [209.85.210.70]) (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-1.canonical.com (Postfix) with ESMTPS id 2E8EB3F0B9 for ; Fri, 13 Aug 2021 19:08:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1628881723; bh=H8dIEB3LRbm3iYcaTBXsF5OMfg14ogv5reT5Qsjf9TU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WrXGry4J+j09AMZoFLXUrKAiN018a1bFRrKyAVn9ysv5bSzM0A+lHgQBq4G4EAXeU /cFlymBMLaeMZObL2lrCQLcCMRHvk49SBoMUBOgvMaNggO7j3jGUDGob0/xvL6Lf0G 2cpL9p+kd8caoXipnLiWFy9b0FKIs/PjWek/6CLWYwf9BBf2jlz3fPWw6ks/HD7BV0 0JkMpA41ymDsINmLXedKutO3UOUcUjpfdOuomuxl6UcpCK91fE3U+hiovK9dXaDk31 FihLWrP4gXfaFGOa8iWHw2tDU/6zB0QoHBqIf7lff9DXUs+8CTJ5mAfjG9KVFu/cnq HLYUfhX7zeCIQ== Received: by mail-ot1-f70.google.com with SMTP id r24-20020a0568302378b02904f21fcab643so4055844oth.17 for ; Fri, 13 Aug 2021 12:08:43 -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=qaXDK42VEd5K2YB6VYqyn3SSn+EhVKLNn13XCQfWujAelfCA8kA+IXHkIVpLwOE3gA 8myVn/uEUO2eAWiF8zOeOFOh0pcHPUR56qvcH24sXw0hCnd2A9vkd72OfNDE1KqHDwW5 M1/gXYb/ZVsnQvTmNAyeBUE7hA5N7kXaWPTwBERq5QlIVl7hXD65HxeLDvx+iFLwyYmu 7TSBEvMsxJBtpO9lRVMcY06zTYKTpb1vZZe+q7CUrySPNbi1HdDUS4vo06JRjjhUaEck e9QrxJFt2A/jywX0xfuCVPTE5UqW/HXvAl/otE+uCZKEgxoiFU2dFlHeU2fU5lDCpPpb 9Aug== X-Gm-Message-State: AOAM532fdQBG7D8v2BxluK9Uz3meVFssB21SejV1JkVbUQ0pvkB9FdnT PYVeFO2y8dvuLrmo/i2I4hZD7HwPX/10IuhL/kRM66IyKNPXmooL1o2s3OxhuxgvKcHHQV6uhan WOyHj6dIqc3VWW1GqhHKoMFMH8OoJtizus3XH8GuIIw== X-Received: by 2002:a54:4705:: with SMTP id k5mr3401933oik.71.1628881721971; Fri, 13 Aug 2021 12:08:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx43ydINwEAEle/W/rBul3JkQSWQOK7CCDXPYiOziyv7le9HRdilGYvudzrnx4VigYuWnchpA== X-Received: by 2002:a54:4705:: with SMTP id k5mr3401925oik.71.1628881721835; Fri, 13 Aug 2021 12:08:41 -0700 (PDT) Received: from localhost ([2001:67c:1562:8007::aac:4557]) by smtp.gmail.com with ESMTPSA id l14sm431588oos.28.2021.08.13.12.08.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 13 Aug 2021 12:08:41 -0700 (PDT) From: Georgia Garcia To: kernel-team@lists.ubuntu.com Subject: [SRU][Focal][PATCH 1/1] apparmor: Fix memory leak of profile proxy Date: Fri, 13 Aug 2021 16:08:32 -0300 Message-Id: <20210813190832.1992850-2-georgia.garcia@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210813190832.1992850-1-georgia.garcia@canonical.com> References: <20210813190832.1992850-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); }