From nobody Mon Jun 8 20:53:43 2026 Received: from mail-qv1-f45.google.com (mail-qv1-f45.google.com [209.85.219.45]) (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 E03031B6D08 for ; Tue, 26 May 2026 15:35:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779809751; cv=none; b=SgiJE/IcK6o1FhJwGizckVIfADW3DxTZzqzvEA6maJXlNEBSH3fGMMM+70l1ukKVw1mMic1VBvVls2GTm1T7mAF6YF8kbB3+yninUNu0iB2esZZzmvRvgVr7PrB4lphsjgKn3FbHLOfS9oQiK0jGRai+6UVJEzlXcs+O+KgPGS4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779809751; c=relaxed/simple; bh=BdrCyzbp+2MqB2Q45Ge3JlLUe63MVsEBUoIfS6DNtWo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lJrk+6uIrFRr5HuV0MlDmz9VdCyZwmEAreJAg3CU5Ul0yoBJyGcbMxSaigW7+qDEHUWTX5idWZW4WbIzpUilxVggT/xwikjJtXnSPhVg2epFgTvtM+r5Azdh18VL2bx3vb7GCrkoocvc/mCaudPpiNkHOlEi0ifbXDaaNX+JLew= 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=Pus19jnN; arc=none smtp.client-ip=209.85.219.45 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="Pus19jnN" Received: by mail-qv1-f45.google.com with SMTP id 6a1803df08f44-8b7dccd6fe4so103983486d6.1 for ; Tue, 26 May 2026 08:35:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zetier.com; s=gm; t=1779809746; x=1780414546; 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=Pus19jnNWL+jgBZsnVAC/QriICxVXNYCkJ/1EbAFpa7cjpYKFLaTao9qJD5mGnOb1P aGJ8EHyl4CG9wyvp8Sn5TcOfnaCQz3P+EbEyxtriUH5d/4SdknWFRDCemRLa9FEMm7DD U4uaM9cckmgmJ9ROTrx/zuZG5XqAYieYfTPT6GwkvC/XCrc1GKLDbavUeO07MtVxBFhH sH/QtyBD3SzKpAi11SEqQA0/hPq8lHw/AOCnk49DKj5aCSTZg2hJfWWnyzw13XKGZOxk WTXJ4H0pVAvjFbWA+LThoeqW7S3bZ4OyD0iyFxHSJyL6QzwL3V1Ic5JGm2FmsAgcbCRE lNnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779809746; x=1780414546; 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=b2xASFj1WqzQXOIxxWzi7drHqlMwL7K0/tjpYz7DlGs9pNoCVKsiXP3qhf7xIp2dQW goh5BuJ4seD16KlSXktJwn56SnKHEPUv81FaPl+WRth9rxrygYHEGZ70SXWShhhHEXVc Ia0zfpLsGSH4qiiyLe40y+YQi0Trbjs38ZuNVdgWuaNMG6JJjGytbC1Q4fdg43R6NKfZ FuZOb+vsAMn5VFaOg72Fh8QdON1rdM6bYImjy4kHf2VND0A/VLHp5Qn40HpkVrsnO06U YWtSxcewN2/giD3MYA0sGCKdcU2hM7UJrB2bFjRurP60hDgk7cCz3d/6Rtr1Zd6agr2C FAJA== X-Forwarded-Encrypted: i=1; AFNElJ8hcDaohZUgy3fPJXJ1XdlePclzmd413I0twGum573HjbLvjM0/dVJKc+LYV4T9QWbfdW2H/BshU4IyOIo=@vger.kernel.org X-Gm-Message-State: AOJu0YwTEvlHBu5uqMJrSxAdvt1PTKBQ4P1UPlLbuqGytHhDpO2nNZMq EO7fW1DQIrq/K+19MnOljUiDJ6hTbFI2NbUyQipohx7LGoLKmfjATPwxX//TUyg6SCo= X-Gm-Gg: Acq92OE1gBz0zOM34cFLSpx3B6KgBPT0uJtmUKtMQ4bKJa/pCL1VX6Urkt5pWuRBpAu XmGLccQeEZ5bAqZ+bEw9DXplq54bApT+Fj4yB0SITIfqcvkkX/aGFImgjxvqITq0bRrjl1Tjqwf SbbsXasa3H6TmmS3o0TaqQ1VWlXJbPCiYvm6F6pUmPbrvK9JN6jLztcoFhzYyrYcTbR33/4vN4N emx38/YajyG7gmnneJIYswic9hJtOPh7/BEn1iebI+BrhB5FGhaCJOducTHQirbFoS80/AQtTWx J4hn4GUAhQO4LY6hJlpZn2xeDl+xb/RcFMY9W3Tlek/JDk7OD6CRdrh2FAFU3/8pbm/IK5WKioO C4D3C1isGifbmVp4GagVaHHqOJ89IXwjGbdh+/dwYUUs6eudl0hdYYhXP5J8XIwGOcCEhhuYI9p qse4IWP3yp+jaGOWFN3Iu3IayLzfDOC9XWejCe/xB8VhXghxN5KGGJZl9jlY+tIyluDOwe7U5yC EuR6Q6Mgg== X-Received: by 2002:a05:6214:5c01:b0:8cc:ec7:72c9 with SMTP id 6a1803df08f44-8cc7b550894mr321270736d6.19.1779809746352; Tue, 26 May 2026 08:35:46 -0700 (PDT) Received: from warpstation.incus (107.191.145.34.bc.googleusercontent.com. [34.145.191.107]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8cc80dd02c1sm145053886d6.6.2026.05.26.08.35.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 May 2026 08:35:46 -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 RESEND 1/1] yama: clean-up ptrace relations upon activating YAMA_SCOPE_NO_ATTACH Date: Tue, 26 May 2026 11:35:42 -0400 Message-ID: <20260526153542.105483-2-ethan.ferguson@zetier.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260526153542.105483-1-ethan.ferguson@zetier.com> References: <20260526153542.105483-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