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 C2A8418A92F for ; Sat, 9 May 2026 00:48:54 +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=1778287734; cv=none; b=PnHOgSoLaWxPcIyEjFMnYI0cuMuQX7L/vmcTY5/bUUZGpugZOdi2dRPSFoKRWNfgPHTG1SLyvQCE0uj3gqBksYWNHmCwJ8JIzP9qv0Z8w6aNR9pkafGRScr7gVdc5l5SrdLD1fzJPege/JSP36yRvqEig3uaPFq/75nph2S5Y1M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778287734; c=relaxed/simple; bh=RQqR9ysswOLLa/YaWAUfdDAspmZrem/a0PQcrp7FBas=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UDOVcKvruqZGxQ2V6xEFD5jaqv94F7oGOT99epiy3+qyN2x0s7r4ZobOKiuIQIA64eYAg1tTUWTV37vdGOHJ6OBbXerKuBV/xvN2lgpkP7fitHrfP+DgRI0XbZwHr742SN7ISartmPjhmloyqvIXV3iA9ILAyV2hGIuHungNFFU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KvNcG7Os; 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="KvNcG7Os" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9A82C2BCB0; Sat, 9 May 2026 00:48:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778287734; bh=RQqR9ysswOLLa/YaWAUfdDAspmZrem/a0PQcrp7FBas=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KvNcG7OsQvUXd1csg1+Xp52ua6F+GXwNNVfhTsU0MX6kt0bqQ+O57pPCggrBqQ0NN VWB+RG2ezcGx2NoNL0pwEWEsBXs+QnOUJzaivX99OKAwHh3RfUduxekkWoQHy/7hAb PDglBi55tauYcOj3piei/6W2q/YcwCM1N+A/D+0RzR8KK1bT9qbLoGJNoTfm/SVjAi 7/3UQ4rrXGpA4X5T2/gfKsPmFflr6gaw5ivhmv23qO/K68DovLFF81lWC36PH42aoR 4TVeYqWQI3uBrcLtx6yCjk+EArBqtLCzEcSyaF2kSt6eaULbyz8tLIlOXNhdL8ZBvX mvh8J4xXXmy5A== From: Sasha Levin To: stable@vger.kernel.org Cc: Cengiz Can , Qualys Security Advisory , John Johansen , Sasha Levin Subject: [PATCH 6.6.y] apparmor: use target task's context in apparmor_getprocattr() Date: Fri, 8 May 2026 20:48:51 -0400 Message-ID: <20260509004851.2446589-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026050423-contrite-dejected-7705@gregkh> References: <2026050423-contrite-dejected-7705@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 641f6510d7cb0..1b9c646f00754 100644 --- a/security/apparmor/lsm.c +++ b/security/apparmor/lsm.c @@ -664,25 +664,23 @@ static int apparmor_getprocattr(struct task_struct *task, const 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