Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6737996rwi; Mon, 24 Oct 2022 05:36:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5zmUOkD3MbqlVdA8KlWHfPYpm7Pd+nWl49zkuL81PySQgUSey0b4S2QIrwd7kijPehqji9 X-Received: by 2002:a63:8641:0:b0:46e:c693:2e57 with SMTP id x62-20020a638641000000b0046ec6932e57mr12790809pgd.341.1666615018798; Mon, 24 Oct 2022 05:36:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666615018; cv=none; d=google.com; s=arc-20160816; b=PI3ULtEJW/z/hpFzY1u1chSwT+GS6n9g1Qure7PxwgeFYTZtgaUbYAFQ1748qUnsJP y6c9jTMgy/gIFgUBHKdIKAz3qtDtl1jbexIArjnxsr/scemX1Z7g+2rj07pgNLCCu1gY k52RtEji8ovt+PUloxeWw+HKFm/gqkZwKhBQ62oz9epvcWQ9Q2/5jxDTww6a9hfRbuHK Ggs3cgW4T75mvOzXuKosSiGy9DftSPvW663kVvr/IWv4LzYKaKEAevgY3lmBZdkCHBLj ToGs1JBetr9AFxHgFO4Rf0V+B0te87iuFXa6ADJ9O4ZF+aTavnFXAMlVghwkn8uOgoAC IbdQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t16-20020a656090000000b00461f124bc4csi35162454pgu.86.2022.10.24.05.36.46; Mon, 24 Oct 2022 05:36:58 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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--;