From patchwork Mon Oct 16 15:34:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Falcato X-Patchwork-Id: 13423597 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F643C41513 for ; Mon, 16 Oct 2023 15:35:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B1901940007; Mon, 16 Oct 2023 11:35:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AC8DE8D0001; Mon, 16 Oct 2023 11:35:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9906E940007; Mon, 16 Oct 2023 11:35:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 845968D0001 for ; Mon, 16 Oct 2023 11:35:02 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 58B51B549D for ; Mon, 16 Oct 2023 15:35:02 +0000 (UTC) X-FDA: 81351722844.24.2741D35 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) by imf19.hostedemail.com (Postfix) with ESMTP id 912981A000A for ; Mon, 16 Oct 2023 15:35:00 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=N7Xs21eU; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf19.hostedemail.com: domain of pedro.falcato@gmail.com designates 209.85.128.54 as permitted sender) smtp.mailfrom=pedro.falcato@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697470500; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=wB7/iWqEpIuTjd3/Y3wkGwJ3ek+RrsFECJqLSfrqbjo=; b=s7SBjC+xRPXBv5KJ6EApviaXBG5b+f8YyAc74DnoLeQnpbXHmgG/o6JIKTDRrqpjlNHbvc sj6xQDPIT0bLiwLFWzz+1nq1A3428kGi6UFli3yrCpyfYZ5FojArJNYSc7YnkUdwpDn2Ef obUAMNk9rjdnnYSIGN1G/8oMz4Jjp+Y= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=N7Xs21eU; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf19.hostedemail.com: domain of pedro.falcato@gmail.com designates 209.85.128.54 as permitted sender) smtp.mailfrom=pedro.falcato@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697470500; a=rsa-sha256; cv=none; b=3bDil11pKMs/cMc3gAtCOwHz5RaAjd6YmEHokQQX9oronr+MfIK7C2f3eq/uJseX8aByJq 4z4hYYxReBx+bIEnpgqYljSuEmPAmQSTZD681foYAE2gvbseGNKp1+ymnVGquykmbAsJaY FzpjY7xV0r+7axkor4D2/YI79s7IDN4= Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-40572aeb673so45786235e9.0 for ; Mon, 16 Oct 2023 08:35:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697470499; x=1698075299; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=wB7/iWqEpIuTjd3/Y3wkGwJ3ek+RrsFECJqLSfrqbjo=; b=N7Xs21eUb6PExLuMMf3klQxleEkBfHNq/VR76o3Uq36rhtTsP+pSjbSOgpsBW88bwi JyVtfHVGIYA+lGuiO2/ki/CZvFBNK5Kx2gJ5DBstI0+PnvAb85cffu0sSIuGyrqx5wY/ gvPiGhzdvNin3M34sff6WG3ceoNh2lxGsonxO1WDIVmRd3LT0v+9vThZveVUTOXCDMt4 OjHKJcVHksKR4OjK14pR9HZFMao4juhIzedIudlt0H8U3YfizQqijxDnDh9lkL7ePIhX ieIY27GUIK/qfA3rGnCHTKfwDuIqTgSXbosSip0hn0cJEoDdAYKLvsbDKvBqLE6fzkKg cxWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697470499; x=1698075299; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wB7/iWqEpIuTjd3/Y3wkGwJ3ek+RrsFECJqLSfrqbjo=; b=piZxHu0VPHr4TYBR9HqqpOBNTIcD/T0IfChQ+Y82cgPi78AceFeH1/wbR1blJX8v7u NCxYj7N5Qq7w8Xe+Nwp1HIU25tv3p2x7QllywwY6FBdUd/VHy9Gzz1VjcxVN6Sal8wWZ 6O4mH5jnuw93wpT8ilwLWSlGM1ursXZ3haN1XeF+QtJS3JlY5WuhZX1Cg+15zF+VdUT7 GjoyL5mrn3uoUVTmDxaWhIWZ70uH/TggdjOq1sSUF5XS2PL1x0bj8E/6go1HJR2MaDFm SylfAWa9Bh8lIyKEvf8dxoWbtGpj9yKPJpcQs1yL2MGQwgfXJ264OmdvA/NlktVarrcC o8+A== X-Gm-Message-State: AOJu0YyXpATmYB+yoBY4OmSz5Ztnuvfyb49004LnwdHhX1kUoJhrhg3N vlWj16G0V5EITKD5BJkQdJI= X-Google-Smtp-Source: AGHT+IENykvCYMH2GUFFnk4c9myhQF291xXM25TEAoR7zDZCDmEgtPOhszVuBAFmH/sAs6yrQpJLwA== X-Received: by 2002:a5d:420a:0:b0:31f:bdbc:d762 with SMTP id n10-20020a5d420a000000b0031fbdbcd762mr30244049wrq.44.1697470498637; Mon, 16 Oct 2023 08:34:58 -0700 (PDT) Received: from PC-PEDRO-ARCH.lan ([2001:8a0:7280:5801:9441:3dce:686c:bfc7]) by smtp.gmail.com with ESMTPSA id bx7-20020a5d5b07000000b003232f167df5sm1955283wrb.108.2023.10.16.08.34.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 08:34:52 -0700 (PDT) From: Pedro Falcato To: kasan-dev@googlegroups.com, Alexander Potapenko Cc: Marco Elver , Dmitry Vyukov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Pedro Falcato Subject: [PATCH v2] mm: kmsan: Panic on failure to allocate early boot metadata Date: Mon, 16 Oct 2023 16:34:46 +0100 Message-ID: <20231016153446.132763-1-pedro.falcato@gmail.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 912981A000A X-Stat-Signature: 4inx4ud3ek9qmgpx17sgftdhkjoxmkkg X-HE-Tag: 1697470500-760594 X-HE-Meta: U2FsdGVkX18J39WrTxvjUkSf1rAuOh+5NIXBSQctoemX+XDpZt0dSXrwsaIivGiFY5n1v2VP1p4q4W1I5S3IK7ZxRHwp7c6E3JRXYU0iQvIkjTooQUDpsbepGVVCeJLKVWCQ81DUBdI1V5enDqNz8GRRjVc+XW5onKXcBCX1xLWt5cQbrWKGf7HjcBmkZeXprTtdcIqxcdCgtgRm6nPKRLHz6b1/oFAnof9k0PQ5yFUKr/onPI2MXD4w4EGtdT86+mYb06ghaJerKxKxIZ3NtSPYJtOsdOvHfgm3fT8j/sgQ5+Wb7UyDXII/QFqrMI8vbB3TeWt2buLsXxyjt8KFU8vRFg59H9+XknUIqCQU8UdYTGNV35jz0/GyiCCc3+IE+XnpH+oJOhwhivF7mb5HErBUbtS2qAVd2txhGBMP/6UUsNn1pJUcj8KposIzWih/28V29PfOJPbo0Gf/pZ0Ku6NjXWlbjLnMepTQP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-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Given large enough allocations and a machine with low enough memory (i.e a default QEMU VM), it's entirely possible that kmsan_init_alloc_meta_for_range's shadow+origin allocation fails. Instead of eating a NULL deref kernel oops, check explicitly for memblock_alloc() failure and panic with a nice error message. Signed-off-by: Pedro Falcato Reviewed-by: Alexander Potapenko --- v2: Address checkpatch warnings, namely: - Unsplit a user-visible string - Split an overly long line in the commit message mm/kmsan/shadow.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mm/kmsan/shadow.c b/mm/kmsan/shadow.c index 87318f9170f..b9d05aff313 100644 --- a/mm/kmsan/shadow.c +++ b/mm/kmsan/shadow.c @@ -285,12 +285,17 @@ void __init kmsan_init_alloc_meta_for_range(void *start, void *end) size = PAGE_ALIGN((u64)end - (u64)start); shadow = memblock_alloc(size, PAGE_SIZE); origin = memblock_alloc(size, PAGE_SIZE); + + if (!shadow || !origin) + panic("%s: Failed to allocate metadata memory for early boot range of size %llu", + __func__, size); + for (u64 addr = 0; addr < size; addr += PAGE_SIZE) { page = virt_to_page_or_null((char *)start + addr); - shadow_p = virt_to_page_or_null((char *)shadow + addr); + shadow_p = virt_to_page((char *)shadow + addr); set_no_shadow_origin_page(shadow_p); shadow_page_for(page) = shadow_p; - origin_p = virt_to_page_or_null((char *)origin + addr); + origin_p = virt_to_page((char *)origin + addr); set_no_shadow_origin_page(origin_p); origin_page_for(page) = origin_p; }