From patchwork Mon Oct 24 11:29:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8419 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp400367wru; Mon, 24 Oct 2022 04:47:00 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7qP5TRTF7UZa27OZ3pb98Svy/L6Pv28NCqy1QxvHR2Yw4e1BCs9PmcaJuqGGEQznHDxJr0 X-Received: by 2002:a17:907:2d91:b0:78d:8747:71b4 with SMTP id gt17-20020a1709072d9100b0078d874771b4mr27231797ejc.545.1666612020349; Mon, 24 Oct 2022 04:47:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666612020; cv=none; d=google.com; s=arc-20160816; b=qKdXUXVzmIJ27fNj+LNB0QQF1UdFt5XTYuZGHZCsPEVbRkRu2dFSxY0kK3XtpAlYX/ CECwYTCPpe5KQvukZAK/zf1BciBhvmFehIVRIbBzLjA/Qfc/oD+dZM1rOM8jLRauT6uD No+IQjQHajqdZX2R3BAf21kIYzOO501J3ARA+DYts2neTFcntQ7KSMjX9yZxMvJ/PvU0 Mhk1Z2TUSLqzjTR1EUXQ/90KZHTOVlBflS4ZeykxG7xXlZeNtvHR66XG2uHP73aIfMbB WlYwwJejHPE4KFZXBnfcIQsVjpBYALKETdzUtfxxgECBfBVd5WXY+AYU3RIPxt3LtbVe kcIg== 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=z2Skj2vkVLCB9W18JinorXAb8uA8mx6NNxYygaa3+rk=; b=gGaJm9+hoJ8dANM4vdl4FJ2Y4DAqBJ3wAOJl8jhtzyPP+OKmjCD1dge+zFBR+kDQYy WVaLdDBHH694Km9ccG94K4JQduZojfVGJdsqRfjw+enRiy+Pu06zW52jIab7vyobQeuY zjpVhtI8fVUOs1w3F8sY1QihNXGRbzbIGqKhbSEPWzsrCIrrtNiV9Ut9m0mBm9AsNWBK e1uute83FGs28gR8GM8nX1RToinBUgXAqvBbXp+lYSZWl+8/9yqUabu9sDS2dcuEc104 tsC7v/mQTSP6C99RXO/H9VNi0ir7n2SEk/cMBwJ2wB/OT2Lc6Hb1yTCUOwN4aZXJn6z+ jB3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mIWd6O4X; 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 s19-20020a056402015300b004597b778b3bsi23586099edu.75.2022.10.24.04.46.36; Mon, 24 Oct 2022 04:47:00 -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=mIWd6O4X; 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 S231202AbiJXLqG (ORCPT + 99 others); Mon, 24 Oct 2022 07:46:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231686AbiJXLoP (ORCPT ); Mon, 24 Oct 2022 07:44:15 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F5BA72FD1; Mon, 24 Oct 2022 04:41:26 -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 C42ADB81145; Mon, 24 Oct 2022 11:39:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28F0FC433D6; Mon, 24 Oct 2022 11:39:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666611545; bh=obetr8wuqaOqOKyX/zRzc+21RtJy+aLxcpblzYfxrQE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mIWd6O4XQ4EkmSUBoH98VoL+Gj96ayNIJuMA3R9rHIUwmgwKaIqslOlzgCzSo5YSv EwnG83vOjAMrnOE/nPsoulCp1w5ioRv4DJTpNFwYxgfFMTtJAXEPeOHaPWQO67rYY0 B/Hm0OtFTyFh+Tw78HvQdXMUlqr6rZZTnNDFxU84= 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.9 007/159] mm: prevent page_frag_alloc() from corrupting the memory Date: Mon, 24 Oct 2022 13:29:21 +0200 Message-Id: <20221024112949.627999696@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112949.358278806@linuxfoundation.org> References: <20221024112949.358278806@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?1747569365732403837?= X-GMAIL-MSGID: =?utf-8?q?1747569365732403837?= 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 @@ -3987,6 +3987,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--;