From nobody Tue Oct 05 04:23:20 2021 X-Original-To: dev-commits-src-main@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 452D812D6BBF; Tue, 5 Oct 2021 04:23:21 +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 4HNkwT1YHWz3Psd; Tue, 5 Oct 2021 04:23:21 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 15019260CA; Tue, 5 Oct 2021 04:23:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1954NKcX087851; Tue, 5 Oct 2021 04:23:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1954NKmZ087850; Tue, 5 Oct 2021 04:23:20 GMT (envelope-from git) Date: Tue, 5 Oct 2021 04:23:20 GMT Message-Id: <202110050423.1954NKmZ087850@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Wojciech Macek Subject: git: 3ac5012e52ee - main - sdhci: Fix crash caused by M_WAITOK in sdhci dumps List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wma X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 3ac5012e52ee3d9abf9c18e1302d8c6851858fd2 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by wma: URL: https://cgit.FreeBSD.org/src/commit/?id=3ac5012e52ee3d9abf9c18e1302d8c6851858fd2 commit 3ac5012e52ee3d9abf9c18e1302d8c6851858fd2 Author: Bartlomiej Grzesik AuthorDate: 2021-10-05 04:22:32 +0000 Commit: Wojciech Macek CommitDate: 2021-10-05 04:22:32 +0000 sdhci: Fix crash caused by M_WAITOK in sdhci dumps In some contexts it is illegal to wait for memory allocation, causing kernel panic. By default sbuf_new passes M_WAITOK to malloc, which caused crashes when sdhci_dumpcaps or sdhci_dumpregs was callend in non sutiable context. Add SBUF_NOWAIT flag to sbuf_new to fix this. Obtained from: Semihalf Differential revision: https://reviews.freebsd.org/D32075 --- sys/dev/sdhci/sdhci.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sys/dev/sdhci/sdhci.c b/sys/dev/sdhci/sdhci.c index 7806a08a1572..4a59a73a7e26 100644 --- a/sys/dev/sdhci/sdhci.c +++ b/sys/dev/sdhci/sdhci.c @@ -264,7 +264,11 @@ sdhci_dumpregs(struct sdhci_slot *slot) { struct sbuf s; - sbuf_new(&s, NULL, 1024, SBUF_AUTOEXTEND); + if (sbuf_new(&s, NULL, 1024, SBUF_NOWAIT | SBUF_AUTOEXTEND) == NULL) { + slot_printf(slot, "sdhci_dumpregs: Failed to allocate memory for sbuf\n"); + return; + } + sbuf_set_drain(&s, &sbuf_printf_drain, NULL); sdhci_dumpregs_buf(slot, &s); sbuf_finish(&s); @@ -340,7 +344,11 @@ sdhci_dumpcaps(struct sdhci_slot *slot) { struct sbuf s; - sbuf_new(&s, NULL, 1024, SBUF_AUTOEXTEND); + if (sbuf_new(&s, NULL, 1024, SBUF_NOWAIT | SBUF_AUTOEXTEND) == NULL) { + slot_printf(slot, "sdhci_dumpcaps: Failed to allocate memory for sbuf\n"); + return; + } + sbuf_set_drain(&s, &sbuf_printf_drain, NULL); sdhci_dumpcaps_buf(slot, &s); sbuf_finish(&s);