Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2619507pxm; Mon, 28 Feb 2022 02:51:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJzANxmanQuUHaSsStK7ayJyO9piPpKfa1/rrrb2gcjn23iUGd7je4O/9O9JbhurrR3UIpCk X-Received: by 2002:a05:6a00:1a56:b0:4f4:1a2a:6d1b with SMTP id h22-20020a056a001a5600b004f41a2a6d1bmr1293258pfv.65.1646045463868; Mon, 28 Feb 2022 02:51:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646045463; cv=none; d=google.com; s=arc-20160816; b=jDthQGPdznf+LBrbBhrvbqEfLeNW+dhUPx6+RvgSPF7znZAdu1uYzdB1VmDbPaM9KW dch5I4jq3HMf7x4qTdPM0CGGyqN3w68Cm+uABCuGxVVaFYTmfMTKnSBv+vcurup9RT8M cWWtRhg+mSG6vXsit/Mmz1mTNHa6zPmK03NcQ1EwTG/RY+bVjgQcD7rDSHfOKV/TaWAL 4eStiDpzMPmRMNqBBfo3b0I2Tfjw/SGV8/fLMYLK/wP/TQtJf6w1liMzEPvkgKjO8qNb S22eacLBtG8xHMWwifpQ6am0D1A6aPOvJER1FgIcEilMPQ1m24znoxat5a2ZmbKi27Ih BC8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Mu4z0K7hpkoqgqdclRigMyBEeZ29kUN9ssnH5fqcZQE=; b=uc6cR01Mi19ODo3jrEujKmvxRkw6a+kx67dUm49/r098vBmcLMRCiOPzrCtgqndXgo MAYPlSSB6SNtpOzHOz2z3toBmE7n2wRzYJhsNkuENvM6guG5DvWvmeIzJU5jKS/hJ3C1 C1bV5tSJ6C6T3StmA7PYeNKilLHjxJus887CzifoxkUjwCU5wmBKJ8XjdOh2qRWEQErz 1s5cOD76M01W7HUxWxiQMe7r9AJBjZi4tBf+FHSgP47l1S7wQ6LVYuV8QvCPVpDL6lVE iV+ksLMcRdB0HzyPWqcsmdAiHVTeXtHiM4QvjjFbsUCtFoCGkp5m28s1ti7L1I6l21MM h0Cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ZmrPa37c; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i9-20020a63e449000000b00373aa082ca2si8629587pgk.189.2022.02.28.02.50.48; Mon, 28 Feb 2022 02:51:03 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=ZmrPa37c; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233621AbiB1H1o (ORCPT + 99 others); Mon, 28 Feb 2022 02:27:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231347AbiB1H1l (ORCPT ); Mon, 28 Feb 2022 02:27:41 -0500 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D058666AC7; Sun, 27 Feb 2022 23:27:01 -0800 (PST) Received: by mail-pf1-x430.google.com with SMTP id y11so10322028pfa.6; Sun, 27 Feb 2022 23:27:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Mu4z0K7hpkoqgqdclRigMyBEeZ29kUN9ssnH5fqcZQE=; b=ZmrPa37c+Rc73oAqIjoShfBAFOZTvK1o8tQcfNrdcK3m6Ntrd1PM/ajCIG/iwsCVo4 VxsFqD9qXZNUut3zfAys4mGmJ4WRoKBshMUGhW934z+TE3cNlTfghzRZX8gERnSV5fiB dsR/o4OUTz+2OgHlmlz736hFvWSWBTEZEW0X/KcbjMwsz6kwLKjKZfb4HqvEMNYv8awN pjZRPxmMosTEW9PDwAWNMrbJXN5zrftksiBENS4UDVHZ/35WiY18uYnYthbsIab7zFEF M7gRa6MEGFyVJFEG1U4bllz2EApLdCuWqsDUMtzwJFrc1edd4E3MHfQqPL4ekZM4D2yr RbNg== 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; bh=Mu4z0K7hpkoqgqdclRigMyBEeZ29kUN9ssnH5fqcZQE=; b=5I6ZhO/N4bZ9oDub7gLT2uvxDKjL6Oo5W9NubfMC7wwYO5oB4r1A/Vv6NoTnFbZ7KK a+vID2KsQmZrJi3PUEfdRBYuNjn8o1WJgj4R/wuOWg9PaE7XFirKDqohI9CiIC3/OB7o qqZYJYdeXIZsRtgN/whHEVZPWJ5sORblFI4XJPUwvjSJXJa3PzPnhlbPSZuHcqkErMo/ /OrIHGTYD1SBePPHf4Tm7Jbyr7ua2biOaw2a9O0J5Lhi8zSJcG0emja70v+Pf816YM2G Lg4Kfv8Hpr8lvqs7Y8EfnVbZYHo3sxtO2gBrvRGqtfEF5yJa9L+3lbNeKYt9vKb7euCD M/YA== X-Gm-Message-State: AOAM533m0+KT8SuyTHRtQKshk+H9wRlGccEjbVrE1sKHeRpp4mrjquRm 8AtqGjkHZroUaK1zJhxuGHQltdgzj9tD8/Ss6lI= X-Received: by 2002:a65:6bd4:0:b0:374:1fe3:e18a with SMTP id e20-20020a656bd4000000b003741fe3e18amr16132117pgw.621.1646033221378; Sun, 27 Feb 2022 23:27:01 -0800 (PST) MIME-Version: 1.0 References: <20220224103852.311369-1-baymaxhuang@gmail.com> <20220225090223.636877-1-baymaxhuang@gmail.com> In-Reply-To: From: Harold Huang Date: Mon, 28 Feb 2022 15:26:50 +0800 Message-ID: Subject: Re: [PATCH net-next v2] tun: support NAPI for packets received from batched XDP buffs To: Jason Wang Cc: Eric Dumazet , Eric Dumazet , netdev , Paolo Abeni , "David S. Miller" , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , open list , "open list:XDP (eXpress Data Path)" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Thanks for the suggestions. On Mon, Feb 28, 2022 at 1:17 PM Jason Wang wrote: > > On Mon, Feb 28, 2022 at 12:59 PM Eric Dumazet wrote: > > > > > > > > On Sun, Feb 27, 2022 at 8:20 PM Jason Wang wrote: > >> > >> On Mon, Feb 28, 2022 at 12:06 PM Eric Dumazet wrote: > >> > >> > How big n can be ? > >> > > >> > BTW I could not find where m->msg_controllen was checked in tun_sendmsg(). > >> > > >> > struct tun_msg_ctl *ctl = m->msg_control; > >> > > >> > if (ctl && (ctl->type == TUN_MSG_PTR)) { > >> > > >> > int n = ctl->num; // can be set to values in [0..65535] > >> > > >> > for (i = 0; i < n; i++) { > >> > > >> > xdp = &((struct xdp_buff *)ctl->ptr)[i]; > >> > > >> > > >> > I really do not understand how we prevent malicious user space from > >> > crashing the kernel. > >> > >> It looks to me the only user for this is vhost-net which limits it to > >> 64, userspace can't use sendmsg() directly on tap. > >> > > > > Ah right, thanks for the clarification. > > > > (IMO, either remove the "msg.msg_controllen = sizeof(ctl);" from handle_tx_zerocopy(), or add sanity checks in tun_sendmsg()) > > > > > > Right, Harold, want to do that? I am greatly willing to do that. But I am not quite sure about this. If we remove the "msg.msg_controllen = sizeof(ctl);" from handle_tx_zerocopy(), it seems msg.msg_controllen is always 0. What does it stands for? I see tap_sendmsg in drivers/net/tap.c also uses msg_controller to send batched xdp buffers. Do we need to add similar sanity checks to tap_sendmsg as tun_sendmsg?