Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1505177rwd; Thu, 25 May 2023 13:42:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5siPfRnIjWWR8kwbB3qGAGUn4L/SOyJikjYoKMzgyqmi/5LYB9kd5WqbG4V7SEWVBfxIyO X-Received: by 2002:a05:6a00:98b:b0:646:e940:c2c4 with SMTP id u11-20020a056a00098b00b00646e940c2c4mr11319977pfg.14.1685047325952; Thu, 25 May 2023 13:42:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685047325; cv=none; d=google.com; s=arc-20160816; b=crR4Su/ZhIW3kHxgobgvAHLCclvtepxupPfi2SMXa+p2E4BtNYaruLBp5zqzC/p1Rj 6rThPFY23OGDzjukzoY1Ldd6PGddEJXiZjmcNbScblplBWE8sJqTdgdVk5I16kddvEqy wUUjOXhHlRgTqfiaQEn16Wa5B+YDYikyOv1YSjciqmwjvRldPzn8b1dnanEc9h2SE5dT yYy7xOvPiZWcvfGgWRwnx1eCXRsBlZ00qhYzTOvqhrDVzL2ktqfj94hhKXKyjcAnUjiu EUvxL6XdqmnmIVRsoFTrrtG0dpaj9DjmaHBGQMHo8kBc/Y/33Dt9sQeMwTLkTKSVBc0i o5QA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=7GenWYLPOmh/DxUR71oJ2OvVJUeCOFtnm9yoLhzSJ/E=; b=NgTpT95Hw80EkDN+nQXR6S2SbJGjkwH2uAdSdgLcqfPYSETayPrzb2O9gTDHHC8Q99 e7mM1MFcgRkdoEhNewYPa35kZ3dNhB8Ua8fubMmCJCjk/ijwXj454Ff8FUg/Wws3/mQY bwTzodp++cOGNgZs1Dyu9d6Vg/gj3IeODXoNLEdkhFZRthq7kembZ2uLv05qGbkSKQ9i 8H6UhxS59pUOhGcuPSSB+sOpzUDN9vr3XQ9m39oZBhqLlj1qecUGkpX9XcfVn+Ov0QhS V5R73aKVxnQhcIBOVQoPq/dLTqhM9SWgO85STiS1sGpa8hY9yl0Ms/hNiH//sH3OmU9R vgLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=NKPfoDYr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g4-20020a625204000000b006251fb701a6si2165429pfb.285.2023.05.25.13.41.50; Thu, 25 May 2023 13:42:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=NKPfoDYr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241261AbjEYUEf (ORCPT + 99 others); Thu, 25 May 2023 16:04:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239074AbjEYUEc (ORCPT ); Thu, 25 May 2023 16:04:32 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DA95E7 for ; Thu, 25 May 2023 13:04:25 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-5112cae8d82so4384269a12.2 for ; Thu, 25 May 2023 13:04:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685045064; x=1687637064; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=7GenWYLPOmh/DxUR71oJ2OvVJUeCOFtnm9yoLhzSJ/E=; b=NKPfoDYrdLeFmk2aRdYPxqPS5pW5Nof94OU1LE1k7d3n4+RuYbf3dtZX81FOmgTzK/ sLqfSBI/22EKUNuB9g5jJppihQiMCTHpCAjwXsmhXtkj7d+i9yGG1LSsR6AgbrBB5UXT e0zmsgoIEjRNkt2fkd4ya7KKCjNLr9lg8cN+F2jG/l1XD59r5DafHGcOQ51T9kbH5vkY mj2noB7t5Dc2KaLxoFwmA9wSI1RWdtvYDd6NF50EgdGVbU5BpSTgKMATR8gkiK1H/GOe Ti89wsXJSop7ACz+Fo5qcA5ZcWuH8SO+wbchq1LkFwAqIwPAdo6dkpOPQubVVV5qemGi fH5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685045064; x=1687637064; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7GenWYLPOmh/DxUR71oJ2OvVJUeCOFtnm9yoLhzSJ/E=; b=YvCNxSXNC9BD5uF8gOjm8JQOiJHQ6RxNrRMTIxVzwZDLMsNZfV0qD/uNNudJZhC06o gcSK7uefVuaRWm23iwCv67U9YuOYJow4pGEjbhA1QC7r/FIbaqmfqrNcLhMFooSQLX9l gHq8s6igv2kUbQRvC8I3BHB/GxROqtOIfX/NVSe9P8ln0Q25//GKpEsdD8JN8IVJBfa6 UgqY2DEO+GEWnlbq0B5sz7M+B0dPBgX6dzlpsu/WJ5IcGeSHULuGs6BrEm7ockRvLXeR lMxniqJJb7mK+oNza3QyvgGfrxv3pI/uCDnaectfr1LBf9XhW5pJ4EVY+wzbclYWsTQO K+FQ== X-Gm-Message-State: AC+VfDyBje/C7uXtmf3jYre1YbS26m+UQERkBH+FV4CSeAhdUTLioib+ YMtn9424X4QTJI+0cpkhD40ETkAjGmRv0Y5Hp+iM+xXJ9mc= X-Received: by 2002:aa7:cd79:0:b0:513:53f7:8ca2 with SMTP id ca25-20020aa7cd79000000b0051353f78ca2mr6245246edb.9.1685045063476; Thu, 25 May 2023 13:04:23 -0700 (PDT) MIME-Version: 1.0 References: <20230524082424.10022-1-lstoakes@gmail.com> In-Reply-To: <20230524082424.10022-1-lstoakes@gmail.com> From: Uladzislau Rezki Date: Thu, 25 May 2023 22:04:11 +0200 Message-ID: Subject: Re: [PATCH] lib/test_vmalloc.c: avoid garbage in page array To: Lorenzo Stoakes Cc: Linux Memory Management List , LKML , Andrew Morton , Baoquan He , Christoph Hellwig Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 24, 2023 at 10:24=E2=80=AFAM Lorenzo Stoakes wrote: > > It turns out that alloc_pages_bulk_array() does not treat the page_array > parameter as an output parameter, but rather reads the array and skips an= y > entries that have already been allocated. > > This is somewhat unexpected and breaks this test, as we allocate the page= s > array uninitialised on the assumption it will be overwritten. > > As a result, the test was referencing uninitialised data and causing the > PFN to not be valid and thus a WARN_ON() followed by a null pointer deref > and panic. > > In addition, this is an array of pointers not of struct page objects, so = we > need only allocate an array with elements of pointer size. > > We solve both problems by simply using kcalloc() and referencing > sizeof(struct page *) rather than sizeof(struct page). > > Signed-off-by: Lorenzo Stoakes > --- > lib/test_vmalloc.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/lib/test_vmalloc.c b/lib/test_vmalloc.c > index 9dd9745d365f..3718d9886407 100644 > --- a/lib/test_vmalloc.c > +++ b/lib/test_vmalloc.c > @@ -369,7 +369,7 @@ vm_map_ram_test(void) > int i; > > map_nr_pages =3D nr_pages > 0 ? nr_pages:1; > - pages =3D kmalloc(map_nr_pages * sizeof(struct page), GFP_KERNEL)= ; > + pages =3D kcalloc(map_nr_pages, sizeof(struct page *), GFP_KERNEL= ); > if (!pages) > return -1; > > -- > 2.40.1 > Uh.. :) Reviewed-by: Uladzislau Rezki (Sony) -- Uladzislau Rezki