Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6742012rwi; Mon, 24 Oct 2022 05:39:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Heg+Vaa0hpTbdnH0LcbHvvm+16kENzWYmW5ldpg2dHLCxiA6Drnfx0PRaCRbTF6Z0l4fT X-Received: by 2002:a17:907:2d06:b0:78d:50db:130e with SMTP id gs6-20020a1709072d0600b0078d50db130emr27238959ejc.371.1666615175510; Mon, 24 Oct 2022 05:39:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666615175; cv=none; d=google.com; s=arc-20160816; b=SUMrwel49QVDC/dbXOqFRhQEfnEiEfxJC7nNmZn46vmsmn82bcdSWuWX/eQU1ztyIQ eFTQB0PMBhnaIJAYhMXecyGNPyI3in99lnQ1eYsYv9AF2sKgyBKFanTPqAXylgGZ+Gf1 rtncFdSFwbeiGuV4ifv84P8RxDFITbvyUEAtAV7CUWlmCvvegtXZE6zH0WmMpvN2D4Wx t/Zai9QM85Us5D0el9z50ph0vxVD85S/b2yOhdSa/wAM9CAAbTz7eL4BvUHOcEP86sWz WzRHf0B9tkiExVFlJGi4RvNxrlMK6vRALYNClop6xRfkUY8/sHCk84yQWZT5Nl25KTOl O3sg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y7-20020a056402358700b00451e1aae675si29203196edc.547.2022.10.24.05.39.10; Mon, 24 Oct 2022 05:39:35 -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 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 @@ -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--;