Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2146003rdg; Sun, 15 Oct 2023 13:27:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFgr7VFmLeuoAfZdkAamlefM+FCUKwMb0WrAtA/jdFDF2y862wSj0WoV7hNOJdMT8dcIUBE X-Received: by 2002:a05:6a21:6d9f:b0:13f:b028:7892 with SMTP id wl31-20020a056a216d9f00b0013fb0287892mr35505108pzb.2.1697401629586; Sun, 15 Oct 2023 13:27:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697401629; cv=none; d=google.com; s=arc-20160816; b=BpMrqnYJroY0F4+4z8bxMCIzKFfINiEztN/K5nKfaupHG4rh6GeUZ7aDjmSYrKS0nX poO1VcJOtOMpPeRNPt3n374crLBqpQWGEMx5utayNvkqmSkHfa7mJtriM9VfjY5VQdrS oZlWYGu0CLWaezpD7Y6vjiSxlc3iPPjuRJhAqoxetxKslBOPEHTtbfRzaArVTzcAVvn3 Kluw+CHJsWHacenij1OiGdUZyfYn/Jg/BjCBFLWPs0EqtGIxNI9rWpmt4JpxxrNYvg7l cwM2blDDMDt9ZNHF27N6LYCsNGBD+HigA5lw4MGlIQWGbK/NuF/hLl0EC6b5FxwFX5kW sZdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=9mJQUt7Wf0+dPq/8JTeI94cIlxhXMv5ZBTCjETmdTqU=; fh=8wIzoGKF/8WwnpUbhDb2usV0+hxy+4E6rjXfhoczKno=; b=Qkm5SPhXUd1f5XtFAhDZtIx4XPVozkXqKUJ0bf3MtjbV95Gvua2yqdgJLhQ6uqR3jL d5NeQfl5M2Zv1DsIT73qEoIgoTi5jUmXMUDuMrdHDAfkXRHsTWVSP7ydiVxZwShoLiav m0vr8HE3iTXaAI44OpwMc87RS1Z5uqjwQxUT/gVsgScgKxwf+V2tzjdOQasmQQq9WGag usCXtyEEKOfNqDW1VUaXTRY8z/JchlXtOqum+augdrFq5lwapU1g2sSQsWhikAKu1bQP 144OoghVurVobTAZr3kG5XA6ItlpNU3sp22Pxftxcwh11oSrBLl6t3cZnY6G7kn5en33 upIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=fP8Sj+Zm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id k4-20020a170902d58400b001ca5a337339si2181464plh.627.2023.10.15.13.27.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 13:27:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=fP8Sj+Zm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 304358057DA4; Sun, 15 Oct 2023 13:27:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230378AbjJOU1A (ORCPT + 99 others); Sun, 15 Oct 2023 16:27:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229990AbjJOU07 (ORCPT ); Sun, 15 Oct 2023 16:26:59 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 955CCC1 for ; Sun, 15 Oct 2023 13:26:57 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-32db8f8441eso24292f8f.0 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=vger.kernel.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=fP8Sj+Zmgowryvn3edaUpvRhj5ctaNKQFZeTysSjAZKduvzY/o+aQ6Jj0kMakxC0kT RMVBkwehKFD4d0cEdjDRQAYqJtlnU5aWr/vk9kKeFJRkxWSy4N+r0y5ytkuRzNaSycFr /mBzW5GQtaGoEkrRFVgr/yV1fAwQFYPWWrTyc7aVln2QIz+/I2vBCyvmHeUvqWWm+oud pGeh4ROzyk0Np/O5cjxAkt6ZA3vAHbkHefCvL0XVO8gN+9ym9Jl58nmyFMGPWD5X3O/u XRE18d0uTbEfvk5fMm77esD/uH00Ui1qigGEGvUwqNCfqJy//Gy1V5CHqy6hlnowNL3D Mr1A== 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=jCWCaR1QEN4VxxYebUF9l0K5d3ow4tDIcYV/+vCi3hG4QELmUL2y3SD31pEnHoSXA9 pnlVAsl6Xli7+etOTyvZtS2aUwEl3DggHOs2eUiFLCv+Cjh3l4exb4nYDlF7IriR70Gq 6kPbEWf6A/rj2rKVT48YkDc663R5rClXEGvSoq+p/Ixq087dlF78yXbZp6zvXI3pDKQY NqvePKkn1/7lzyOB1Fgqo0rRhlBEnKYJt0MlUEVXCysvFJn4XykeS4gTL241rnV5UuAH hMt7b2Si7IVrQHWEAVlAOinzXDseMyAiKn7M8uobwOLCZdEXM7jreeUI+aWg8B7kZXH8 zQ6A== X-Gm-Message-State: AOJu0YyxZznIPSOeO2TCMLee6m8JkSkzkQObWBUTHy7p5UvlOI7Pneak oxGaQADkIEgcRGYYG+6seDE= 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Sun, 15 Oct 2023 13:27:07 -0700 (PDT) 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; } -- 2.42.0