From nobody Sun Apr 16 20:47:48 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Q02M25vMcz45wjn; Sun, 16 Apr 2023 20:47:58 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4Q02M13p1wz3jgN; Sun, 16 Apr 2023 20:47:57 +0000 (UTC) (envelope-from kostikbel@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.17.1/8.17.1) with ESMTPS id 33GKlmfJ086018 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Sun, 16 Apr 2023 23:47:51 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 33GKlmfJ086018 Received: (from kostik@localhost) by tom.home (8.17.1/8.17.1/Submit) id 33GKlm1s086016; Sun, 16 Apr 2023 23:47:48 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Sun, 16 Apr 2023 23:47:48 +0300 From: Konstantin Belousov To: "Stephen J. Kiernan" Cc: src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Subject: Re: git: 4819e5aeda4e - main - Add new privilege PRIV_KDB_SET_BACKEND Message-ID: References: <202304161838.33GIcJiX079190@gitrepo.freebsd.org> List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202304161838.33GIcJiX079190@gitrepo.freebsd.org> X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-14) on tom.home X-Rspamd-Queue-Id: 4Q02M13p1wz3jgN X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-ThisMailContainsUnwantedMimeParts: N On Sun, Apr 16, 2023 at 06:38:19PM +0000, Stephen J. Kiernan wrote: > The branch main has been updated by stevek: > > URL: https://cgit.FreeBSD.org/src/commit/?id=4819e5aeda4ef1a193a08e29b4099c3c30369a81 > > commit 4819e5aeda4ef1a193a08e29b4099c3c30369a81 > Author: Stephen J. Kiernan > AuthorDate: 2023-04-16 03:59:52 +0000 > Commit: Stephen J. Kiernan > CommitDate: 2023-04-16 18:37:58 +0000 > > Add new privilege PRIV_KDB_SET_BACKEND > > Summary: > Check for PRIV_KDB_SET_BACKEND before allowing a thread to change > the KDB backend. > > Obtained from: Juniper Networks, Inc. > Reviewers: sjg, emaste > Subscribers: imp > > Differential Revision: https://reviews.freebsd.org/D39538 > --- > sys/kern/subr_kdb.c | 6 ++++++ > sys/sys/priv.h | 7 ++++++- > 2 files changed, 12 insertions(+), 1 deletion(-) > > diff --git a/sys/kern/subr_kdb.c b/sys/kern/subr_kdb.c > index ff981cdfe47c..8aae19b728c8 100644 > --- a/sys/kern/subr_kdb.c > +++ b/sys/kern/subr_kdb.c > @@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$"); > #include > #include > #include > +#include > #include > #include > #include > @@ -484,6 +485,11 @@ int > kdb_dbbe_select(const char *name) > { > struct kdb_dbbe *be, **iter; > + int error; > + > + error = priv_check(curthread, PRIV_KDB_SET_BACKEND); priv_check() fails for jailed, or even simply non-root process. kdb_dbbe_select() is called from a random context, e.g. from kdb_alt_break_gdb(), where it inherits whatever thread was running at the moment of break to debugger. In other words, this function no longer works reliably. > + if (error) > + return (error); > > SET_FOREACH(iter, kdb_dbbe_set) { > be = *iter; > diff --git a/sys/sys/priv.h b/sys/sys/priv.h > index 20bfc7312ce3..cb4dcecea4aa 100644 > --- a/sys/sys/priv.h > +++ b/sys/sys/priv.h > @@ -515,10 +515,15 @@ > #define PRIV_KMEM_READ 680 /* Open mem/kmem for reading. */ > #define PRIV_KMEM_WRITE 681 /* Open mem/kmem for writing. */ > > +/* > + * Kernel debugger privileges. > + */ > +#define PRIV_KDB_SET_BACKEND 690 /* Allow setting KDB backend. */ > + > /* > * Track end of privilege list. > */ > -#define _PRIV_HIGHEST 682 > +#define _PRIV_HIGHEST 691 > > /* > * Validate that a named privilege is known by the privilege system. Invalid