From nobody Wed Aug 02 13:15:43 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 4RGCHP6Wf9z4qbD4; Wed, 2 Aug 2023 13:18:55 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RGCCQ0GLbz3jCB; Wed, 2 Aug 2023 13:15:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1690982146; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lXZ4iARTntSaqu0hOLNvCFmA1EZOm+hv7d8OTMoSkvY=; b=YhCkHlREYqGDIbr3YFoeUmEMtWzINXO5MYRuHfSQAtIQ/1MIZwU1CdhcrzVP1m23GXh3Rj DMX7ct3uVqN+L/6zzeEEBCpOJgPdSSO4HHtraxpRSvZQLgohEytMs55wjMgHyOLe/mwdhL GFSa9vqD7+HV8tgGGrA9hzkzx8iEt19Hq3OKhfRAslqWZHfzMK+kVi2mvVy0Fo0Q2093y+ iV/6XMB1LwLgFqFiMUIzUQKtWjyGPk+gRvazQbE2i8FTxgCMKDzPeEc8OuWA5fVHcI6nF9 AJOLwDePIdLEOxFKs5HOnQ0m8OTUpugCN+2cTWbQ7QUwXRbQDNev78GyXA1S6Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1690982146; a=rsa-sha256; cv=none; b=yasqS4PEjcHtj67fD+5GD5BNlEcBfA+L/s+pKPeu9K8Tuj+3d7aScBhjL0cBxIz55Gd62l RBWnZnJcavqwX27XzURkHiBltDyhqLEkei2uJZkuRaiZKKepkprQ5jyh/g37/rBX+TUqnc W1FM5bvzNyqHI++Qke/c0VogkjeUlrYWP/lAFmj1HR12ZrW1ZICp0iu2vpKOkRmGntYU0H 6ZweRg3TbHlUP552wUZswKDyy03qZHqZdAdnpKc8bvH9tyIiuE2GU9DvQcSJ26ozBcYQg0 iIhuuHQmkS/65BtW0oGnaBOSzT0oCVmKymGdBG0ZP2Jhnzc7FAOAbOnnnceFuA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1690982146; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lXZ4iARTntSaqu0hOLNvCFmA1EZOm+hv7d8OTMoSkvY=; b=d+oqAV0ap2PAa5Yv85JiaPtXqMxl4VYjtHHJs3+RgzN6PS3eIRc4gkK4tuDuJaXWXj6+AQ CjAncVqDikJFtMA9wP/v9y6hXbu6McL2KeIcDYPJTJdwXi6f0F4vXXbTTbLpiHN1XZJbL/ Ktjuhqm/vsHz3JYN1D/Kq1/kBjKjgaC9kq+qTjYw1asf2FZoV1O7xyjmvASQU0HAoYS4gs AAdfFVjRBSpDWiIf7GcUbeDdoXc7DJKHMdpOwXZrjnnN5z/5HugT8gQBU0ezHZgrdb32o6 rEakOz/13dBEUFs4K31hCQ2gNF1e268a4FM65JXUwvacM5ip8wJfXvMyeiqRew== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4RGCCP4wmKzLMq; Wed, 2 Aug 2023 13:15:45 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 372DFhrR021597; Wed, 2 Aug 2023 13:15:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 372DFhNs021596; Wed, 2 Aug 2023 13:15:43 GMT (envelope-from git) Date: Wed, 2 Aug 2023 13:15:43 GMT Message-Id: <202308021315.372DFhNs021596@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: bd16c274c382 - main - kdb: Permit a NULL thread credential in kdb_backend_permitted() 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=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: bd16c274c3826926108f0539b5043c5a811cad43 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=bd16c274c3826926108f0539b5043c5a811cad43 commit bd16c274c3826926108f0539b5043c5a811cad43 Author: Mark Johnston AuthorDate: 2023-08-01 21:58:42 +0000 Commit: Mark Johnston CommitDate: 2023-08-02 13:15:08 +0000 kdb: Permit a NULL thread credential in kdb_backend_permitted() Early during boot, thread0 runs with td->td_ucred == NULL. This is fixed up in proc0_init() at SI_SUB_INTRINSIC. If a panic occurs before then, rather than dereference a NULL pointer, simply allow the thread to enter KDB. Reported by: stevek Reviewed by: mhorne, stevek MFC after: 1 week Fixes: cab1056105e3 ("kdb: Modify securelevel policy") Differential Revision: https://reviews.freebsd.org/D41280 --- sys/kern/subr_kdb.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/sys/kern/subr_kdb.c b/sys/kern/subr_kdb.c index 2f419b4d8ad5..dda21d53b6a5 100644 --- a/sys/kern/subr_kdb.c +++ b/sys/kern/subr_kdb.c @@ -503,11 +503,19 @@ kdb_dbbe_select(const char *name) } static bool -kdb_backend_permitted(struct kdb_dbbe *be, struct ucred *cred) +kdb_backend_permitted(struct kdb_dbbe *be, struct thread *td) { + struct ucred *cred; int error; - error = securelevel_gt(cred, kdb_enter_securelevel); + cred = td->td_ucred; + if (cred == NULL) { + KASSERT(td == &thread0 && cold, + ("%s: missing cred for %p", __func__, td)); + error = 0; + } else { + error = securelevel_gt(cred, kdb_enter_securelevel); + } #ifdef MAC /* * Give MAC a chance to weigh in on the policy: if the securelevel is @@ -776,7 +784,7 @@ kdb_trap(int type, int code, struct trapframe *tf) cngrab(); for (;;) { - if (!kdb_backend_permitted(be, curthread->td_ucred)) { + if (!kdb_backend_permitted(be, curthread)) { /* Unhandled breakpoint traps are fatal. */ handled = 1; break;