From patchwork Sun Oct 15 20:26:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Falcato X-Patchwork-Id: 13422329 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 7B499CDB47E for ; Sun, 15 Oct 2023 20:27:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 992558D0006; Sun, 15 Oct 2023 16:26:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 93FF28D0001; Sun, 15 Oct 2023 16:26:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 82F278D0006; Sun, 15 Oct 2023 16:26:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 7135C8D0001 for ; Sun, 15 Oct 2023 16:26:59 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 3F448A0892 for ; Sun, 15 Oct 2023 20:26:59 +0000 (UTC) X-FDA: 81348829758.08.5C7C960 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) by imf22.hostedemail.com (Postfix) with ESMTP id 81AFCC0002 for ; Sun, 15 Oct 2023 20:26:57 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=MywMKtzE; spf=pass (imf22.hostedemail.com: domain of pedro.falcato@gmail.com designates 209.85.221.44 as permitted sender) smtp.mailfrom=pedro.falcato@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697401617; a=rsa-sha256; cv=none; b=CSlpwKkXDElSKxZBOS0Aw8SLdJVUxktnV4bUspcujmPRumIrNaS5AlMYDFGVsX/MhgT6Le fCInvJdHDWWgNVYFeJZRXEbeJ4S5adM+PfDDDhD9bo+60j4swgDPbJcSi6WIP9b+K3lNq7 ozpDBGpey8SmOj/quTijGIZ2v3+7uBs= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=MywMKtzE; spf=pass (imf22.hostedemail.com: domain of pedro.falcato@gmail.com designates 209.85.221.44 as permitted sender) smtp.mailfrom=pedro.falcato@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697401617; 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=9mJQUt7Wf0+dPq/8JTeI94cIlxhXMv5ZBTCjETmdTqU=; b=uMtROW8avJBE5uqPWx0OFifACDeop4uizmB1J1z5tXHGc1FUnmfmTQD1DVOruMVEiXlVRo sXxQFSecn7/6q2f1rJVBlH2lX36NIC+CqhS+1AxXacRZOTrtTefQVX+nSHsI+ib8qrV4Pg 5gBhvEO7IYTc0JVzsv8u6l0WI2L7k+k= Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-32d849cc152so3693707f8f.1 for ; Sun, 15 Oct 2023 13:26:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697401616; x=1698006416; 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=9mJQUt7Wf0+dPq/8JTeI94cIlxhXMv5ZBTCjETmdTqU=; b=MywMKtzEcNx20z1LZBzkRE94VksxhDJeNMOxCeWCN4srNakr99KBr8cQRE5FdyWCbK b8RTjDo0R0gnZy2IKuG9MRAERdDUM3moSL1UqQase1zen1L+O2CQpszO/uf0hWLuKFrf qt2BdZWoxbvQrlr1RYSVgHTHElre/HzMxL96+dG9FXfXGQnO1vhLkoKnScCLHVi1s97a rZ9t4sxQ/Sn2ExLObQSpS2yE9IH9YKjl+OPQZJlDpx7ak7Ue5hcrztzsTAOsiiYj1WQm FVBY9Vw294mvY+Nwvjw57y7s3VS387KKHT6Vbe6nSKT8HNANXrWNBTm+SY66+7A1Pjvy ZysQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697401616; x=1698006416; 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=9mJQUt7Wf0+dPq/8JTeI94cIlxhXMv5ZBTCjETmdTqU=; b=oHcdMzBcyVYNpyZLn84A8k3jBz0HM+LzHbcwpHKP3JXo2JagK6gtwIwu3gIMYXVBuY JNNeJ8W4Czmzb9db4z+wOWqAqhvJPkLHZgtonfe81IGI9qiHsctoE4qtLbmkouzpk4ja 3YYRtUZ36ku5WyolVq6eMAsRyPJjEGr64RKjKGL7pGR5x3VvRJTzZJWj2OpjtC1CHPBg A9Sh3ouRZWAqK0ZfXGXqFbuHFyXK/ILNXetDApsKeRxOfMXJw1eib5yeq1bEQ/HbKKiZ QRKiOfY0jynD6cHRSgVkgnvAz1rN9Ba2q3kpGB3bKAW5pN74YR/JxKaEAECdChLl1RjV G39w== X-Gm-Message-State: AOJu0Yxt+P8Yp328ee68+3MSI0SfXJKp1Oj3jG4taz3NgMgjbg0JDQMe bCmkW90SLK77krGiCtZKUtE= X-Google-Smtp-Source: AGHT+IE39XZwC0ne09DLeEYAEDmDf3xkSkL6BIj3dVUMU1+rWVkbO5e5YJUqWsPJnfwvd93Lb7r9Yg== X-Received: by 2002:a05:6000:1189:b0:321:6936:c217 with SMTP id g9-20020a056000118900b003216936c217mr26180665wrx.14.1697401615768; Sun, 15 Oct 2023 13:26:55 -0700 (PDT) Received: from PC-PEDRO-ARCH.lan ([2001:8a0:7280:5801:9441:3dce:686c:bfc7]) by smtp.gmail.com with ESMTPSA id u1-20020adfa181000000b0032da49e18fasm4303429wru.23.2023.10.15.13.26.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 13:26:55 -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] mm: kmsan: Panic on failure to allocate early boot metadata Date: Sun, 15 Oct 2023 21:26:50 +0100 Message-ID: <20231015202650.85777-1-pedro.falcato@gmail.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 81AFCC0002 X-Stat-Signature: ogbc5fpyiu5idppq8atr93em6hsry71h X-Rspam-User: X-HE-Tag: 1697401617-660677 X-HE-Meta: U2FsdGVkX1+tTjnYo5tTTWrWEv0rC2iWTr1OhFLsI7FV3/+KfL2VyGYd1W9hT5FKxkTYhi0FLfA2mA6RJXrbfpN67qfbHfAr1AjAOZkng7eVVufYmrKqlT570AYKikGosTAEVmx7ET+Gom775YYa9ZOPngX5jJz5JsUGK3OALs4qkhzJoscxlrMTrTwhNpmxdXKLnHjrkLP09c90Gc6J2yQnmxiBaYM6PijI8fbAeQEsCqjI1ql+6e8WFTGWblxkzDaUPs7XibUnVJpF56PskntqSE56QE6PfW3cGAXd+nPxi5Fvx/N6LhD7XkW8CYmAn5ShJRZOW52tCilSGited4RWVk5iIIrwNOAouPF/baFKp57k2tpPlDi3WQQWkRYEIwePr9NDAm1rI5gXj1Wfmkl5zmJfWqZ/8u9GEXb+BPFF6mWBZHDBrqyXeBIEmkcotjVgH8YBPVqY2ZW+XCTl13ggm75VFFF/4oEQdt9J9u13U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=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 --- mm/kmsan/shadow.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mm/kmsan/shadow.c b/mm/kmsan/shadow.c index 87318f9170f..3dae3d9c0b3 100644 --- a/mm/kmsan/shadow.c +++ b/mm/kmsan/shadow.c @@ -285,12 +285,18 @@ 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; }