Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3387578imw; Mon, 18 Jul 2022 07:15:27 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uS7LrtMOMGcbIgEEYxFChpYma0WSqRdzTwUleFpWfs7oQntLFIn0EKOkEiYg/su4YJ/ixr X-Received: by 2002:a17:906:149:b0:712:c8:fa53 with SMTP id 9-20020a170906014900b0071200c8fa53mr24410283ejh.563.1658153727044; Mon, 18 Jul 2022 07:15:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658153727; cv=none; d=google.com; s=arc-20160816; b=yWKnMwlXFE46AG1N+3heI/mtZDVTfz6AGGqsuIT/LWMkFETpLS5ZRw5rvCQ6zKbW86 szKUnJpELujaKIqPNjyq03Ku8qCLppAajzwrOsTRipZ9mLGqq9HrvVG5MKjZ0M5l/Fip c4qvl5iCU4EoDYATWMLTuBcVS1f7X5kVOJ1pyHi8nUmwcTnRVO0/K+vO1g5JQ5eUQT9/ c5Y1aIAYldpxD4zdjB5ZJovbDWNhKrg6KZSyodja0RJrRBPg28PxkhSUyQMPAxHTY3zI YWM/Nt/jfA91o+lGtNv1O9lShEekSkvN6WIj7+98ksSYZwvpI46/qwlBoYL5MvsMMYPE OrlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=4BCVM5Y1TUNST7laSoOUsYzA69zl5+oV0vJFLfHEP9Y=; b=bFU1I37tHB1RkzZngK+z3iSuHsJkWDwYPPustJqsnSYu83HK5QUsp/xlMZ7yFw0yLl wvxzaRhbMHM5mG/iadD9s4UtcrXJo7sdN53HWXmWSQMQnxHs7sGZHPVcVh/wyG8ry8w2 FfFGDWkhDxuBKojTs88B7LfDYPNyfwyrPEE6gXH5iU/9U8rlRj91x1EJEB9myJWprTnt O8TmkfUMENJ+M89wWR0DNtky5qydwUv8wwbcFZ1fYX/GaPhQN/ze99glZZlKdmx7sv7S D3PMjB4UinGw6UHdqBA2CGGLJu33N+tscvMlnQ/u8NYOPTBM8juVKTJdonEz+ZfNJ2/z H61w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fdMsNyof; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id la25-20020a170906ad9900b0072b49fe5a49si14635659ejb.372.2022.07.18.07.15.02; Mon, 18 Jul 2022 07:15:27 -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=@redhat.com header.s=mimecast20190719 header.b=fdMsNyof; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231274AbiGRNu5 (ORCPT + 99 others); Mon, 18 Jul 2022 09:50:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234524AbiGRNuz (ORCPT ); Mon, 18 Jul 2022 09:50:55 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CBF7C275DF for ; Mon, 18 Jul 2022 06:50:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658152254; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4BCVM5Y1TUNST7laSoOUsYzA69zl5+oV0vJFLfHEP9Y=; b=fdMsNyofurpv/4e4XmP9Nj2OZ4iD8sscH5CSBSkPXvOM3CWn2RJZHCHQ4pNwkqG84Oc63r AXX0bMDjVB3Pnv38ZtwMzBUO/ApPKGIB6wwmHH7qPneXLfIjwpRrhFWWsTSlZEHZ2xz9FL Ix8wY9TWJZbZAvzOyFFeKr5uyI1YTGo= Received: from mail-ua1-f72.google.com (mail-ua1-f72.google.com [209.85.222.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-587-UqlIkuKVN8at8N-nPuEgtA-1; Mon, 18 Jul 2022 09:50:52 -0400 X-MC-Unique: UqlIkuKVN8at8N-nPuEgtA-1 Received: by mail-ua1-f72.google.com with SMTP id 33-20020ab00424000000b003829f08fd3fso5694588uav.22 for ; Mon, 18 Jul 2022 06:50:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=4BCVM5Y1TUNST7laSoOUsYzA69zl5+oV0vJFLfHEP9Y=; b=v91HsLWNA81tyFPwSLYp/KM+LGA0PhLP8o+iEAyShsvRvVccrfZuAPp8DTaF6weIZs hYmDepc7X0+2nhU/meucb9gzSmhErBoe3sHkjoJZBXmm9+jKYy07KyqsSLU+56NPOuPk Ca/ew8yjCgJSvVyFUKvNUaZgjMZHu70sq3W/+qGvreJGP0DM5QGrXH2TYRAXIx/ACTFT fDzI8K8wueNq49mWZEK6yIEkZD1YX6/AxPZl/pnfmmBAoiy2KEXL9rIrWOrmsycWZ23B vwliHsMBj2zjgcT8JIRTc+3uAvkZJK8rbUJ9b8OjgebMX+4wtkhGPQL5xky1EBMVWT2d 2lkw== X-Gm-Message-State: AJIora8b+f50AMM8ivZNyOWK5GN2ZKhVyaaWZmZnBXDuIEB81lhjjz8H +SI59ZP/DzJr/RJfh/vO7fwy6G0+GPOvPC+sez16t/iDH8hAYzznCky2jwWgaUYxy7vc289snKS oLCoAx7xkBBbiwkLzWeKclqWJKIuGg5bQaJOLN5DC X-Received: by 2002:a05:6102:346:b0:357:79f5:63ae with SMTP id e6-20020a056102034600b0035779f563aemr9672750vsa.40.1658152252226; Mon, 18 Jul 2022 06:50:52 -0700 (PDT) X-Received: by 2002:a05:6102:346:b0:357:79f5:63ae with SMTP id e6-20020a056102034600b0035779f563aemr9672738vsa.40.1658152251972; Mon, 18 Jul 2022 06:50:51 -0700 (PDT) MIME-Version: 1.0 References: <20220715125013.247085-1-mlombard@redhat.com> <5a469c5a.8b85.1821171d9de.Coremail.chen45464546@163.com> In-Reply-To: <5a469c5a.8b85.1821171d9de.Coremail.chen45464546@163.com> From: Maurizio Lombardi Date: Mon, 18 Jul 2022 15:50:41 +0200 Message-ID: Subject: Re: [PATCH V3] mm: prevent page_frag_alloc() from corrupting the memory To: Chen Lin Cc: Alexander Duyck , Jakub Kicinski , Andrew Morton , linux-mm , LKML , Netdev Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 po 18. 7. 2022 v 15:14 odes=C3=ADlatel Chen Lin naps= al: > ---------------------------------------- > If we can accept adding a branch to this process, why not add it at the b= eginning like below? > The below changes are also more in line with the definition of "page frag= ment", > which i mean the above changes may make the allocation of more than one p= age successful. > > index 7a28f7d..9d09ea5 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -5551,6 +5551,8 @@ void *page_frag_alloc_align(struct page_frag_cache = *nc, > > offset =3D nc->offset - fragsz; > if (unlikely(offset < 0)) { > + if (unlikely(fragsz > PAGE_SIZE)) > + return NULL; > page =3D virt_to_page(nc->va); > > if (!page_ref_sub_and_test(page, nc->pagecnt_bias)) > This will make *all* page_frag_alloc() calls with fragsz > PAGE_SIZE fail, so it will basically break all those drivers that are relying on the current behaviour= . With my patch it will return NULL only if the cache isn't big enough. Maurizio.