From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AFD911A6823 for ; Sat, 9 May 2026 01:12:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778289178; cv=none; b=OMvcK3JOVPM4Rx6QK1YFqsLJEZzBSJXa+5xG1g6lajS4nmIgIIrgq7QIionQ9GDoSPchxuNT1+dGFD67a4L4kNKigZ/M4FiYMXFteXWYvCFWgwYWGTr3JCfJYnb+ChdzSGTfMh/Zn5+BId8P3YlZ9OOivJlNKJbP94Fx12VE8AY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778289178; c=relaxed/simple; bh=+EI/DdsvMyP+B26j8djy4XD8j8k57+JO+YAG3hSIAc4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B3voiaoO86PwPl1nlK2rZvQXwgnKahCoVBhEbh4AZ3HkOFdtj1RqUUgqWqpko2O0CB6BBj6pKxuhAQfVCRamb+MAqnG/QgstAPCzsCSIiZUZJJTRhaNhfNmOo2+N4M9LCY9z4iduwIqNy70w0/8xcX9hPCu/wOf0U2ilOQrN/gY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=s15gEKbW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="s15gEKbW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C53B9C2BCB0; Sat, 9 May 2026 01:12:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778289178; bh=+EI/DdsvMyP+B26j8djy4XD8j8k57+JO+YAG3hSIAc4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s15gEKbW+YnRabn1naqkpilPhx3PGy+0v/9ZQw8RV1CHYfGdO6YW2WK5Strg7cE9z ItKEM6LlWWd3d3EO0R9KL53zJU3t9Dnc+IihqTydrOJdBaNzCjLAoRTju4fKlRxO0E LBNE3Nbd7tdbKDQ5c7KzWV6o4Ln+B/jqWrRmYnrjfEbn9c5EphXVIGD+ISAb1Dupya ApPxCDeu1VU9IghlEzfwrGSDHUNytLbGKHAN1+C5VTbdcjw8SHBqJ+0QQRjXR54Wqn bI5YW+2GHHItGqQwTeWm8FFFrCKSOKHJ+g3VaS0J+gaV+X1ITG+cyXQxDbJ5LwzD25 IFt9cJbFRI8jA== From: Sasha Levin To: stable@vger.kernel.org Cc: Cengiz Can , Qualys Security Advisory , John Johansen , Sasha Levin Subject: [PATCH 5.15.y] apparmor: use target task's context in apparmor_getprocattr() Date: Fri, 8 May 2026 21:12:54 -0400 Message-ID: <20260509011255.2724005-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026050424-extended-ship-1e65@gregkh> References: <2026050424-extended-ship-1e65@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Cengiz Can [ Upstream commit 4afc61702bdcc3b9b519749ef966cf762a6e7051 ] apparmor_getprocattr() incorrectly calls task_ctx(current) instead of task_ctx(task) when retrieving prev and exec attributes, returning the caller's labels rather than the target's. Fix by passing task to task_ctx(). The issue can be reproduced when a process with an onexec transition (e.g., configured by a container runtime) is inspected via /proc//attr/apparmor/exec. The reader's own value is returned instead of the target's. Reported-by: Qualys Security Advisory Fixes: 3b529a7600d8 ("apparmor: move task domain change info to task security") Cc: stable@vger.kernel.org Co-developed-by: Cengiz Can Signed-off-by: Cengiz Can Co-developed-by: John Johansen Signed-off-by: John Johansen Signed-off-by: Sasha Levin --- security/apparmor/lsm.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c index cf26ffe8cccb7..6d71c1282af73 100644 --- a/security/apparmor/lsm.c +++ b/security/apparmor/lsm.c @@ -598,25 +598,23 @@ static int apparmor_getprocattr(struct task_struct *task, char *name, char **value) { int error = -ENOENT; - /* released below */ - const struct cred *cred = get_task_cred(task); - struct aa_task_ctx *ctx = task_ctx(current); struct aa_label *label = NULL; + rcu_read_lock(); if (strcmp(name, "current") == 0) - label = aa_get_newest_label(cred_label(cred)); - else if (strcmp(name, "prev") == 0 && ctx->previous) - label = aa_get_newest_label(ctx->previous); - else if (strcmp(name, "exec") == 0 && ctx->onexec) - label = aa_get_newest_label(ctx->onexec); + label = aa_get_newest_cred_label(__task_cred(task)); + else if (strcmp(name, "prev") == 0 && task_ctx(task)->previous) + label = aa_get_newest_label(task_ctx(task)->previous); + else if (strcmp(name, "exec") == 0 && task_ctx(task)->onexec) + label = aa_get_newest_label(task_ctx(task)->onexec); else error = -EINVAL; + rcu_read_unlock(); if (label) error = aa_getprocattr(label, value); aa_put_label(label); - put_cred(cred); return error; } -- 2.53.0