Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 5 Oct 2021 04:23:20 GMT
From:      Wojciech Macek <wma@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 3ac5012e52ee - main - sdhci: Fix crash caused by M_WAITOK in sdhci dumps
Message-ID:  <202110050423.1954NKmZ087850@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by wma:

URL: https://cgit.FreeBSD.org/src/commit/?id=3ac5012e52ee3d9abf9c18e1302d8c6851858fd2

commit 3ac5012e52ee3d9abf9c18e1302d8c6851858fd2
Author:     Bartlomiej Grzesik <bag@semihalf.com>
AuthorDate: 2021-10-05 04:22:32 +0000
Commit:     Wojciech Macek <wma@FreeBSD.org>
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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202110050423.1954NKmZ087850>