From patchwork Mon Oct 24 11:28:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8574 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp418227wru; Mon, 24 Oct 2022 05:14:17 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7jbipeyxcovJmqAqQ12eZ3Ca2jQkNd0IxNm3xmd0Yo8qIralWIEmiBM3pQtxlb+qorFJz+ X-Received: by 2002:a17:907:d93:b0:78d:fe7a:f1fe with SMTP id go19-20020a1709070d9300b0078dfe7af1femr28054950ejc.721.1666613657740; Mon, 24 Oct 2022 05:14:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666613657; cv=none; d=google.com; s=arc-20160816; b=JbLU0k6CTulJPX5Rp40QNGcEJ303xFcr8zrZqjNFpqvOoeMiE5872qw7K1aZBfzYD9 Mw/58GdPnI7g4fIiXyYjeJTfgY2CpI43ShNjR9TZ6sYRc0TykYMipga05BYI8Le6CGoC MEItn2iBWvLfZJtYsTRhxBEIlcTO55PPUElGkXy2D57/2g0jCnBE4eEs9Pbjrx0Q1wrZ 4MXk3rmAJ/ufS8OR6HlHCS4TB/FXTIBNHcCPNRBWVVBICLoV4gl7IGs0uy+dcsASCD3Q nLleW+lDRFVuwcU27IHEbuxIYcovQ5mbMWGpyQXwKfB2wwHBMyIk/y9HQbizPgfgyuRT fmAA== 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=HYgl/d2ndUncucSaa/sBDtMeBdn5gZa0kPfjGDjmtxc=; b=tkSuJFX5QZkpczzAJ2Xbq1wTdZjZ7QenW5zMybW5rtkpXNBRUmUSb6DwlxXQOoMImA wSCo1L8Kke3x0ghI5fN+19GI4FlbdXrYG7fe/+uON/kSAiIgenaVLC6NXoInFcKUz7He ibsoT72vaYKpe5JWRqEuTmY8blDrm92o+kc7K7p0OaGo/dX9QhjfVDzc61wxH5d+Duwu NasWMPv0UiawRDeChtcafvHqi6Sb60HF0ketYqorIYJjlU0S+7g0qZYzdFcBjlMraPrX SrjelN/Z+hFa8HqqIvdeNl3Xp5QtI3IQ6lkqHzG03ZknA/GBnbNA2MkCoHzj40bnKqQM Z0AQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OSTTq83w; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dp21-20020a170906c15500b0078df1c345dcsi34064598ejc.535.2022.10.24.05.13.52; Mon, 24 Oct 2022 05:14:17 -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=OSTTq83w; 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 S232554AbiJXMC5 (ORCPT + 99 others); Mon, 24 Oct 2022 08:02:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232784AbiJXL7w (ORCPT ); Mon, 24 Oct 2022 07:59:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 281957CA8B; Mon, 24 Oct 2022 04:48:53 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 5C5C1612A4; Mon, 24 Oct 2022 11:46:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B07BC433C1; Mon, 24 Oct 2022 11:46:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612011; bh=bqt6m1xLhtyg7igUxTT0mC5o4h7myk1GVhOnPHbzFAE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OSTTq83wf82BsAi0l+uWAh59MPwsxiSOX44wWHhZ72p61mr/FgqONDDK0HxNjA/vD cl79YFqMKfOhl+ysA+YA+eNT6E7yYHYp6Il5CmemiWuizKouLbxbgEbwbvYxFGkxXd 1QhbgZyznnGVledpsrSiyCt16iiK/26WVPRPrpPY= 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 4.14 008/210] mm: prevent page_frag_alloc() from corrupting the memory Date: Mon, 24 Oct 2022 13:28:45 +0200 Message-Id: <20221024112957.152189709@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112956.797777597@linuxfoundation.org> References: <20221024112956.797777597@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747571083013328222?= X-GMAIL-MSGID: =?utf-8?q?1747571083013328222?= 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 @@ -4391,6 +4391,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--;