Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp648236rwn; Thu, 15 Sep 2022 04:36:10 -0700 (PDT) X-Google-Smtp-Source: AA6agR4q6kT0hoVNNb67swMrfCVXAiPVp+cK+X0Fp4sxytGvEMEvB1rzat2TQXUjJQS2TVGQs42D X-Received: by 2002:a17:906:5d0a:b0:780:3c42:990f with SMTP id g10-20020a1709065d0a00b007803c42990fmr4759368ejt.9.1663241770495; Thu, 15 Sep 2022 04:36:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663241770; cv=none; d=google.com; s=arc-20160816; b=rQaajXShyrzWWU5iAICP8UAOh3BU0CNPueA7ZIkJHwhyzvjAGZczBFwmW5lCisSS97 g77TsEaqeUHdkAi8rinavcVdRLFkGDRnvWzydIbo2ntM/N/WHXg5Z1Wa7tM2Jm0qjdFn 5cOwqj518Js7xaN6LybZ1UcnJvJz2eYRzmgR/R0Pwt41Ncb8+q7VhLm3aKl+RiKrsNnD kuP7FPQQOgWcC0IWk6AaMVC15v3nr1jIQ11oDvKnH46ErryjRw/977e+xPtWM1jUNT4o XmOOS+srJRZEUE0meD4o3ZqLR4J1zPATyNG+joAO6KDf20uuyOMA2tSsoR7Vd0Uj9efT sHFg== 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:date:cc:to:from:subject :message-id:dkim-signature; bh=+HL5dXGFkel+k2FQJcxVsi3gdKr147k7OQegCjfsQj8=; b=UMRTDjd3OkNZ7LXTJ0EWA1d/pMjIqlIfgF0sy77q+G7UWlFczAaBdp72hCXuS8IP0I pS4C1FgxCP2JgHC0aV+z7L12GenRBB3VTE5BV0bepdQEr+UT/VUSQE7kY3wABRUbvIpf zKessXn8M0sc1eOemEd63sERwFB9OV5ptjlxZ9uWaoVyTyKNYU5ljDIGSnBMqLoEkXHa EbVoei0h0VAqlhamJ+blIG5eFlEXszKktBoluFwWw1uIUqOY3kBqYaBmgjzIKLOW2c6h eLG/mGLN6TWkcwJRSIyL6VMneUdNiXDlfAY70BLdI5ega4l5bdQYgPsZouwUK4WApvL9 i7ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="NyN/QGyA"; 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 fc5-20020a1709073a4500b0073dc770cdc9si11383767ejc.756.2022.09.15.04.35.44; Thu, 15 Sep 2022 04:36: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=@redhat.com header.s=mimecast20190719 header.b="NyN/QGyA"; 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 S229876AbiIOKb3 (ORCPT + 99 others); Thu, 15 Sep 2022 06:31:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229552AbiIOKb1 (ORCPT ); Thu, 15 Sep 2022 06:31:27 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94C3889912 for ; Thu, 15 Sep 2022 03:31:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663237885; 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=+HL5dXGFkel+k2FQJcxVsi3gdKr147k7OQegCjfsQj8=; b=NyN/QGyAzmK4/mKxxl6/MORN0Z8RLWWF9CBGoVxQYUW22eWB3JBrnxGoDt0IDGHvFjronA YNvOiAXL+CQ/+rGrfjBrSAI+lRMnXGfnazRUjDrlOzygyvE48ZkPLP1JxQq0ksjo+ypRmH JwJs+8GrKhdznnoMNPXj56NlV20anxk= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-308-Z2goDqqVOLOPJ4vPVVXGcg-1; Thu, 15 Sep 2022 06:31:24 -0400 X-MC-Unique: Z2goDqqVOLOPJ4vPVVXGcg-1 Received: by mail-wm1-f71.google.com with SMTP id 62-20020a1c0241000000b003b4922046e5so5254431wmc.1 for ; Thu, 15 Sep 2022 03:31:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date; bh=+HL5dXGFkel+k2FQJcxVsi3gdKr147k7OQegCjfsQj8=; b=wtrIv84meuttCMbi4vqTt+5yXiaFqWABLPk/uaGX9TfVyMY/fTSvr/jUopxSVYwOlA 8RuxEglTrrk+tjY575s34bsuh7gIBYmmQHH+c0+C6S2TpBJQuu22RvZVRjxsGISr/WbI OF3h7Gn2WNrw008cBYIniwQrwPid39vRCf90J62bk2hiZfFs5zHIDmJ8M29reokD6llh QQlxgfdxUVj0RvVkORXXqW9toV3D0tV9iyIJC7btZRNGw8QOPMbt9pcS7NmqkhGs3cid 3bQw1NKZQuu83SzQZUABj02C+7ceBDlweaNv40+V4TUNIlrw6gSY/YjSUKc07z/J2KXW 31xQ== X-Gm-Message-State: ACgBeo35FWFSEmao7yGaZrOSsx35gzrJLd2gU+bCpG6NtBLd/nxjv7pD TigLnNya2KSLOzYOR0k3nvCb3fx1b2n2sVD4pmN4hRZOKdh7j72T5OQO9M2bbKs4bzBi8TLh6MD j/hTSHF8P1a1RFa6bIbDuaUOl X-Received: by 2002:a05:600c:6029:b0:3b4:9fcc:cbb3 with SMTP id az41-20020a05600c602900b003b49fcccbb3mr5512265wmb.169.1663237882136; Thu, 15 Sep 2022 03:31:22 -0700 (PDT) X-Received: by 2002:a05:600c:6029:b0:3b4:9fcc:cbb3 with SMTP id az41-20020a05600c602900b003b49fcccbb3mr5512234wmb.169.1663237881772; Thu, 15 Sep 2022 03:31:21 -0700 (PDT) Received: from gerbillo.redhat.com ([212.2.180.165]) by smtp.gmail.com with ESMTPSA id q12-20020a1ce90c000000b003a844885f88sm2201509wmc.22.2022.09.15.03.31.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Sep 2022 03:31:21 -0700 (PDT) Message-ID: <800a1c4eead00b97947e4b289ae49d2858e9f99e.camel@redhat.com> Subject: Re: [PATCH net] net: tun: limit first seg size to avoid oversized linearization From: Paolo Abeni To: "Ziyang Xuan (William)" , Eric Dumazet Cc: David Miller , Jakub Kicinski , netdev , LKML , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Petar Penkov , Mahesh Bandewar Date: Thu, 15 Sep 2022 12:31:20 +0200 In-Reply-To: References: <20220907015618.2140679-1-william.xuanziyang@huawei.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.4 (3.42.4-2.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 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 On Tue, 2022-09-13 at 20:07 +0800, Ziyang Xuan (William) wrote: > > On Tue, Sep 6, 2022 at 6:56 PM Ziyang Xuan > > wrote: > > > > > > Recently, we found a syzkaller problem as following: > > > > > > ======================================================== > > > WARNING: CPU: 1 PID: 17965 at mm/page_alloc.c:5295 > > > __alloc_pages+0x1308/0x16c4 mm/page_alloc.c:5295 > > > ... > > > Call trace: > > >  __alloc_pages+0x1308/0x16c4 mm/page_alloc.c:5295 > > >  __alloc_pages_node include/linux/gfp.h:550 [inline] > > >  alloc_pages_node include/linux/gfp.h:564 [inline] > > >  kmalloc_large_node+0x94/0x350 mm/slub.c:4038 > > >  __kmalloc_node_track_caller+0x620/0x8e4 mm/slub.c:4545 > > >  __kmalloc_reserve.constprop.0+0x1e4/0x2b0 net/core/skbuff.c:151 > > >  pskb_expand_head+0x130/0x8b0 net/core/skbuff.c:1654 > > >  __skb_grow include/linux/skbuff.h:2779 [inline] > > >  tun_napi_alloc_frags+0x144/0x610 drivers/net/tun.c:1477 > > >  tun_get_user+0x31c/0x2010 drivers/net/tun.c:1835 > > >  tun_chr_write_iter+0x98/0x100 drivers/net/tun.c:2036 > > > > > > It is because the first seg size of the iov_iter from user space > > > is > > > very big, it is 2147479538 which is bigger than the threshold > > > value > > > for bail out early in __alloc_pages(). And skb->pfmemalloc is > > > true, > > > __kmalloc_reserve() would use pfmemalloc reserves without > > > __GFP_NOWARN > > > flag. Thus we got a warning. > > > > > > I noticed that non-first segs size are required less than > > > PAGE_SIZE in > > > tun_napi_alloc_frags(). The first seg should not be a special > > > case, and > > > oversized linearization is also unreasonable. Limit the first seg > > > size to > > > PAGE_SIZE to avoid oversized linearization. > > > > > > Fixes: 90e33d459407 ("tun: enable napi_gro_frags() for TUN/TAP > > > driver") > > > Signed-off-by: Ziyang Xuan > > > --- > > >  drivers/net/tun.c | 5 ++--- > > >  1 file changed, 2 insertions(+), 3 deletions(-) > > > > > > diff --git a/drivers/net/tun.c b/drivers/net/tun.c > > > index 259b2b84b2b3..7db515f94667 100644 > > > --- a/drivers/net/tun.c > > > +++ b/drivers/net/tun.c > > > @@ -1454,12 +1454,12 @@ static struct sk_buff > > > *tun_napi_alloc_frags(struct tun_file *tfile, > > >                                             size_t len, > > >                                             const struct iov_iter > > > *it) > > >  { > > > + size_t linear = iov_iter_single_seg_count(it); > > >         struct sk_buff *skb; > > > - size_t linear; > > >         int err; > > >         int i; > > > > > > - if (it->nr_segs > MAX_SKB_FRAGS + 1) > > > + if (it->nr_segs > MAX_SKB_FRAGS + 1 || linear > > > > PAGE_SIZE) > > >                 return ERR_PTR(-EMSGSIZE); > > > > > > > This does not look good to me. > > > > Some drivers allocate 9KB+ for 9000 MTU, in a single allocation, > > because the hardware is not SG capable in RX. > > So, do you mean that it does not matter and keep current status, or > give a bigger size but PAGE_SIZE (usually 4KB size)? > > Would like to hear your advice. I'm guessing that what Eric is suggesting here is to use a bigger limit for 'linear'. Possibly ETH_MAX_MTU could fit. @Eric, fell free to correct me :) Thanks! Paolo