Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2494672rwb; Mon, 3 Oct 2022 01:17:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM73EWWvgcqs+GQvQO/dG4jN7+WW7DXJW0RkEqiH8z5mdZvP2IFYD3MayCWvz8yuVfCYlTWQ X-Received: by 2002:a65:6bd3:0:b0:42b:9117:b9d1 with SMTP id e19-20020a656bd3000000b0042b9117b9d1mr17682845pgw.238.1664785033576; Mon, 03 Oct 2022 01:17:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664785033; cv=none; d=google.com; s=arc-20160816; b=RUZYCCYKB8wSSw5WP9MJ9fBajwMJaWHHVyFAaROnzERJ4WDs+VIaYKGuheVisjXlEI 9kU41s2Uy/k/RlUn/xzSqt2fkPXAEjgyhcrAQ9AWDrMBO1D/kMPmoKv4LVqDpcPos1+6 d/onGJp03X/1DtmSvwg1JHxjmvCaBgNVL64CQhEORTHmnfMDCITtE4C1gEKn97fwL8ND 0o0PbbLpm+2iX7pPtZlvyBiqAnDKe8N8k19t7aJbs647Ms+qAu1k9faJVPL/NZ5I0MHW MUStZil4tI/vSRqM5KDYkfwVk4cJeloPoLHYDfV59foNXiAsthXu9GwbMxlT8neHkmdJ TzGw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=aIVyMND4vCJmw4+L41BKHufLXJm1iadl7LiaMqRcTng=; b=zc+fqc6SBwTuzFasdgidBkmwjqb40G2b3zNne8Ezgx29S0tmUW/teUc/Vqz/5UiXrf ozx8FNZori6ygs6P4DTG/kcUrA5EDjV8wPHXUbZPQ9Z9CgyDbtD1TCh/y7Ts3PLUNvu3 IR2p+2Sad48oIDiAMRwYaVJOIo9KJzFvg8CPHzGB9xi18kc6AdvtcfWDu0289T/+O0ib clsWBCko8oyE/aElqnOn53GvZuD/3OYZbePsFNR96HKueA37EJ08wLtZJSVWyA8wvD+h NZGygIHNYNTZiLB8hB7Wz6JMpFQSagE5AcFDG1mITShle6BzaRkQZ8KS3agvK6uScGTT I4dA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xVKWka1y; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m13-20020a17090a7f8d00b0020a53bc734bsi1177962pjl.52.2022.10.03.01.17.01; Mon, 03 Oct 2022 01:17:13 -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=@linuxfoundation.org header.s=korg header.b=xVKWka1y; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231804AbiJCHkB (ORCPT + 99 others); Mon, 3 Oct 2022 03:40:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231895AbiJCHif (ORCPT ); Mon, 3 Oct 2022 03:38:35 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FA1945F6D; Mon, 3 Oct 2022 00:23:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E90D3B80E84; Mon, 3 Oct 2022 07:21:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46BF1C433C1; Mon, 3 Oct 2022 07:21:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664781680; bh=4rFbnpHEHppa8y3exheq7h2lxPFrxRn7WFEd6SZxt6M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xVKWka1ylgDheXt31LzJKkZIHj0NUberSn/xkqdk/f6bP1uJXnGOHhX0keScoIx7A PT67KLigYsjMlM7y3nYnGF7zumGso6zja6MuSlWhT4g3Cyr8fNwfmoXcI7Wv4bwRIF 5dfDrc2fx34Y+Fo8YwD6mWYtcaqnKKsRD6iEDtCI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Maurizio Lombardi , Alexander Duyck , Chen Lin , Jakub Kicinski , Andrew Morton Subject: [PATCH 5.10 24/52] mm: prevent page_frag_alloc() from corrupting the memory Date: Mon, 3 Oct 2022 09:11:31 +0200 Message-Id: <20221003070719.448461097@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221003070718.687440096@linuxfoundation.org> References: <20221003070718.687440096@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 From: Maurizio Lombardi commit dac22531bbd4af2426c4e29e05594415ccfa365d upstream. A number of drivers call page_frag_alloc() with a fragment's size > PAGE_SIZE. In low memory conditions, __page_frag_cache_refill() may fail the order 3 cache allocation and fall back to order 0; In this case, the cache will be smaller than the fragment, causing memory corruptions. Prevent this from happening by checking if the newly allocated cache is large enough for the fragment; if not, the allocation will fail and page_frag_alloc() will return NULL. Link: https://lkml.kernel.org/r/20220715125013.247085-1-mlombard@redhat.com Fixes: b63ae8ca096d ("mm/net: Rename and move page fragment handling from net/ to mm/") Signed-off-by: Maurizio Lombardi Reviewed-by: Alexander Duyck Cc: Chen Lin Cc: Jakub Kicinski Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- mm/page_alloc.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5163,6 +5163,18 @@ refill: /* reset page count bias and offset to start of new frag */ nc->pagecnt_bias = PAGE_FRAG_CACHE_MAX_SIZE + 1; offset = size - fragsz; + if (unlikely(offset < 0)) { + /* + * The caller is trying to allocate a fragment + * with fragsz > PAGE_SIZE but the cache isn't big + * enough to satisfy the request, this may + * happen in low memory conditions. + * We don't release the cache page because + * it could make memory pressure worse + * so we simply return NULL here. + */ + return NULL; + } } nc->pagecnt_bias--;