Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2519654rwb; Mon, 3 Oct 2022 01:50:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7of69Xa1ks+PK9XQR8zOSxwOv1lo9jrA8B59HJweMXrljIhxH8daEmpdn+wA2MtOtQLhfG X-Received: by 2002:a17:90b:1b0a:b0:203:3947:1a73 with SMTP id nu10-20020a17090b1b0a00b0020339471a73mr11153577pjb.43.1664787010486; Mon, 03 Oct 2022 01:50:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664787010; cv=none; d=google.com; s=arc-20160816; b=Nv/ePznRT5CII/rYrilxAdrWJu0OW6bXs68m9dtTZj0eLTTVIcHAA/Vt7T1zvxRXFo zHVXTGd83Ys55vPS3RYoFvw5tEB8kK3GjzZWTkH2rBJVD3dgPVpMoIrILguB5VxFljaR ZOlKQg2xN/Xi255hOmZJGgtsF02Cn0ZrdoGd53jKxqavpLI98qWRmLV0Ppkw/TfJ3u+c 6zhbRGZIIsrTxKgkNoiTJ2f14wQeS9BeqEO7lWoQyg1vd36ePF6RXZusM0uoRnBYNul1 6S2UHuSYzJ48qBOo5uEHhukKvn+H0TmC7KxysSDKCkxExvz4QMAby0YFsIz/uWEZxp4/ ArZg== 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=Yz6fLJaVCDfI35c/s2xuYOM8iVeExRrCjFu0yDEBPZw=; b=qrD3PFTv0QIwG0X4mt61Jf/y2nyQvln6/QG529KazRQNFsWJg4zc4YoyC9VvWRn/iY GQYb+3MBnKgnm1GD5+oFccLVi80BS1orVNvNlUm1DCFsQ+Cb0fs+HLk5qnyBeB9NLvmS o7JUuf470VN3IDuY7I7I7taZQGeqEXz5kBjF9Pg/tapvuitUD//I/oaIDbBULL9BQ22I hpThLNLMIbLyx822AQ2Rl5vREV3/7mT8gc2ks0kvbzmIZdjtlFpJrPjdeM/OMS2WRgee WKNli3IUnotelEEFE95+bGsJo8SNdFcU9QeKspp3292B+q/UvGp7cs1QjlwQ1XIyXgKL Td0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WptnuLia; 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 l8-20020a655608000000b0043cb40e4696si9257880pgs.692.2022.10.03.01.49.58; Mon, 03 Oct 2022 01:50:10 -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=WptnuLia; 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 S231497AbiJCHce (ORCPT + 99 others); Mon, 3 Oct 2022 03:32:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231406AbiJCHbs (ORCPT ); Mon, 3 Oct 2022 03:31:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7224F4DF03; Mon, 3 Oct 2022 00:20:36 -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 7E3B860FA9; Mon, 3 Oct 2022 07:19:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F994C433C1; Mon, 3 Oct 2022 07:19:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664781542; bh=gx/J8rU/fTa/VktFLUA7AZdk5eUgvudLcIK4l1h2ppM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WptnuLiaeWeUJKAhgbRLavS3ybKd1gXgPKxYr0onGLPDLl+pIe9LTe/3PC84SKP4z Ko3K0G/51+3YylrwFIEbjwxOgPxPjhMXr+aKTEoFds3A/W2RGxzaIkZflU0ei7I3r6 CWMYRHF/g1Qz6BIX0aofUvQ/E81yAl/78s85kqPM= 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.15 30/83] mm: prevent page_frag_alloc() from corrupting the memory Date: Mon, 3 Oct 2022 09:10:55 +0200 Message-Id: <20221003070722.754877734@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221003070721.971297651@linuxfoundation.org> References: <20221003070721.971297651@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 @@ -5600,6 +5600,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--;