From nobody Wed Jun 17 01:54:33 2026 Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F01F147B41D for ; Tue, 28 Apr 2026 19:29:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777404547; cv=none; b=YJlpAtzFO9/y13UALWWxtc7w0/P4gywiD2q0R5KEXrzlIPismeykDuXf94nacBzOHN7IzHauPU3Ek8fgtmfSQmKk9FG1zFZQiqcZzLcI2G+s0jUYUEmJyPHiSSU9AG2Q6UVYhPVLFLTT+S9s3Fi6q/TsMiNXNG/b0iCLsuLylNU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777404547; c=relaxed/simple; bh=BdrCyzbp+2MqB2Q45Ge3JlLUe63MVsEBUoIfS6DNtWo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oYt1que+uH0Kq4lSYnLcvS/Til1o+XdmWhUTkP3c/Z7PpjiSxzWKQBd5HgzLwIEtDDd8zw3uTwKaOHfW6bE32pJ5ut/NiqzXf5OHihSQh9jCXzNZZV1STQMEyJRi4V/sBrcUpl4JeeLxSYWMhLXVG1PBWHyZhzaa4TmiNG6w+L0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=zetier.com; spf=pass smtp.mailfrom=zetier.com; dkim=pass (2048-bit key) header.d=zetier.com header.i=@zetier.com header.b=NOm8yQ84; arc=none smtp.client-ip=209.85.219.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=zetier.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zetier.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=zetier.com header.i=@zetier.com header.b="NOm8yQ84" Received: by mail-qv1-f46.google.com with SMTP id 6a1803df08f44-8acae26e564so141609376d6.2 for ; Tue, 28 Apr 2026 12:29:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zetier.com; s=gm; t=1777404545; x=1778009345; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FaDmpgG4YmKy0EzLVmDS2/ARG0WGlq46PT9Krk/q/WA=; b=NOm8yQ84G2EQvDYz7spOcB/JOgP3rLLdVujUxfiX85SJe+txBtWht6BTAkCU4kb90c /kca7u5nBmgxx/mhuKmaj9NLo7DWOJ0of5I+SZh54oSbDd5flY+hNBnoeH2kXWta5KSp z9MpRYDjLDKFPD9Ar99ytsh7P3Tz9D+FPAZoXWHhHwSQoFtnNd45XB6csS0yMDtF+8vv KXIAHCzzne8B4ImKmc9vIQuLuEYtpz24gjxDO0pVbYobliGY+0k4Dn9JDem8AFmS9rIY CxxVTzW6clvbOd3+ae/kBNRT66leb69iTZSlPO1CyfRQwaPGqVlLqC4CXTvYNSIi7gm2 hz/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777404545; x=1778009345; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=FaDmpgG4YmKy0EzLVmDS2/ARG0WGlq46PT9Krk/q/WA=; b=AzyagzSor2T30KhM/n9nDFai6PTO1zGhXFLcOsr8hFQHF9OYopCLaUeEpfbFPcxAm9 AumCIiYL3edIDYviat9ldBeKsHJQpGNC/aGfQjt+oAZM6+jSW2pv+fKa9mqLOdAtiDZb VONgluq2ujIBrSnlJSBLFoqflYitoXvl3hxj0tinkfQlsf0HkL1oGuHlLq+zzUVSVtwD ZJN2GX8HrL8iZBohi3NLuznCx8iovVoeLoHUWej0kYUOEtCUcpKOkBD4F41y6mBM5F3P iLOgAeSQnx5iEGnKJZ1CVICX1oq6C9w2zpLYvJQSZvmVFCT7F3yB8SnGkqNsfCtq+oAS mtqA== X-Forwarded-Encrypted: i=1; AFNElJ+R/K0PLBv4JVuiLEdY3nZYh39otqa8iFI2PFfGnqX/rzk26HVpWH/MQtV3/DBbLhjdwaNR0Q9PamapcSk=@vger.kernel.org X-Gm-Message-State: AOJu0YxPmgw7qEHNoCE37/3j8vi68Pz2ZYFTrZqMpVIbRutFLfuP7Ete xhv8DMVXqgxBSjnxJknq4iPg8RYU6POVC3j30IyVSTU+egQMpf+4+B3dcgFbduMwKpg= X-Gm-Gg: AeBDieuEaaQgqQNp67m6k1knB8e65xY+8YiMGxKmg6BFBnRlTWztqecwJJR+Uq+i3Vw T8KSZLTw4m46u2YL9qcdoxrDEvVkdwpNj4VmRPFrqPPTWWYB8gwu3Lla7qkyotUjRwKNCWr9tUr mF4Ol9TI5C1Ug+5+P5oP9p4JvlyTGs8njyKqm1ggRxNDnUGpQkoGgouXfLgvaOhj9I6jw4MrogS cjq21KMmtSypShkVqgzStAKAwiHmjGZ/AJaZcmWKf/DfC1b0A7LYy3fMFWwEGorLXGI+Og7aeQf 1Tz535Cfm97GbieY1tALK7ljZMVWsRDnooczS26im3W9YMAWeym2Sm198+4uM92wd/5mE4IWz6S uAutV88vFPkXCLGsX7zzakiPScKJPDkcwgPK1ulCej/Sj/sdtv9gaGSLRRLnG1lCm6ocfMMC6Au VXCKXAUn84skZUyGfllEm2DYKaUj/KlprIVxaiDFWC2p6PmRPN0ijpygvRHun6JkasNnytMqhmK IM0i2Z2X5lKw/vSilYUogjEBQ== X-Received: by 2002:a05:6214:33c8:b0:8ac:af33:a236 with SMTP id 6a1803df08f44-8b3e3098287mr76207046d6.35.1777404544822; Tue, 28 Apr 2026 12:29:04 -0700 (PDT) Received: from warpstation.incus (243.69.21.34.bc.googleusercontent.com. [34.21.69.243]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8b3ee9cec79sm1922826d6.15.2026.04.28.12.29.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2026 12:29:04 -0700 (PDT) From: Ethan Ferguson To: kees@kernel.org, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com Cc: linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Ethan Ferguson Subject: [PATCH 1/1] yama: clean-up ptrace relations upon activating YAMA_SCOPE_NO_ATTACH Date: Tue, 28 Apr 2026 15:28:18 -0400 Message-ID: <20260428192818.1035760-2-ethan.ferguson@zetier.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260428192818.1035760-1-ethan.ferguson@zetier.com> References: <20260428192818.1035760-1-ethan.ferguson@zetier.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Clean up ptracer_relations upon YAMA_SCOPE_NO_ATTACH, and prevent further modification by processes. Signed-off-by: Ethan Ferguson --- security/yama/yama_lsm.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c index cef3776cf3b2..3b7c5384e6bc 100644 --- a/security/yama/yama_lsm.c +++ b/security/yama/yama_lsm.c @@ -26,6 +26,7 @@ #define YAMA_SCOPE_NO_ATTACH 3 =20 static int ptrace_scope =3D YAMA_SCOPE_RELATIONAL; +static int max_scope =3D YAMA_SCOPE_NO_ATTACH; =20 /* describe a ptrace relationship for potential exception */ struct ptrace_relation { @@ -119,7 +120,7 @@ static void yama_relation_cleanup(struct work_struct *w= ork) spin_lock(&ptracer_relations_lock); rcu_read_lock(); list_for_each_entry_rcu(relation, &ptracer_relations, node) { - if (relation->invalid) { + if (relation->invalid || ptrace_scope =3D=3D max_scope) { list_del_rcu(&relation->node); kfree_rcu(relation, rcu); } @@ -204,7 +205,8 @@ static void yama_ptracer_del(struct task_struct *tracer, */ static void yama_task_free(struct task_struct *task) { - yama_ptracer_del(task, task); + if (ptrace_scope <=3D max_scope) + yama_ptracer_del(task, task); } =20 /** @@ -224,6 +226,9 @@ static int yama_task_prctl(int option, unsigned long ar= g2, unsigned long arg3, int rc =3D -ENOSYS; struct task_struct *myself; =20 + if (ptrace_scope =3D=3D max_scope) + return -EPERM; + switch (option) { case PR_SET_PTRACER: /* Since a thread can call prctl(), find the group leader @@ -432,6 +437,7 @@ static struct security_hook_list yama_hooks[] __ro_afte= r_init =3D { static int yama_dointvec_minmax(const struct ctl_table *table, int write, void *buffer, size_t *lenp, loff_t *ppos) { + int ret; struct ctl_table table_copy; =20 if (write && !capable(CAP_SYS_PTRACE)) @@ -442,10 +448,17 @@ static int yama_dointvec_minmax(const struct ctl_tabl= e *table, int write, if (*(int *)table_copy.data =3D=3D *(int *)table_copy.extra2) table_copy.extra1 =3D table_copy.extra2; =20 - return proc_dointvec_minmax(&table_copy, write, buffer, lenp, ppos); -} + ret =3D proc_dointvec_minmax(&table_copy, write, buffer, lenp, ppos); + if (ret < 0) + return ret; =20 -static int max_scope =3D YAMA_SCOPE_NO_ATTACH; + /* If max_scope was just activated in this call */ + if (*(int *)table_copy.data =3D=3D *(int *)table_copy.extra2 && + table_copy.extra1 !=3D table_copy.extra2) + schedule_work(&yama_relation_work); + + return 0; +} =20 static const struct ctl_table yama_sysctl_table[] =3D { { --=20 2.43.0