Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2549860pxm; Mon, 28 Feb 2022 01:03:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJztUae7ilpA1RJqlBAQJmY4Z2TppZrn4lsJ/K6M4L942/H2A6CN5nNkfCrocEzJjBIq3WoQ X-Received: by 2002:a17:902:ba8c:b0:14f:d9b7:ab4 with SMTP id k12-20020a170902ba8c00b0014fd9b70ab4mr19806764pls.23.1646039024162; Mon, 28 Feb 2022 01:03:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646039024; cv=none; d=google.com; s=arc-20160816; b=jnOaYERKH2iZ8qEKy9C4Lpn82eiDcW1zsBKiXkGENUp+6VkA2fRL5jALfcu5l8ymve vyU2PXNjc9WwY8YbGRajH8Ff+DKU8Ub+1coUHtBouU/413HtueY4EnbwZykG2RT1Aos8 EsIX+gbb97BVOcW+90+pcny7EkAhbPp1eU24joYhQuS6Wb5UwS4Mt00IPRyZiArwS3yw 8zGdIvzhGrv0eLByxYmNed0B0tIDoGh2e272/JxMLy15ardPKOaP0id5Ibl0Je9ak14n 2zOmAcpnqYADtjxMcRXZTmmSGEqrmc+zbG5CyUWT52JBoii6wAkNxUgvpCCbqDFqcUVX bUKg== 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=WpShLimVwkmYIyb4Sx/D5oN6uinq/tsyvea/tNkwado=; b=1B2Dmea/PXQptd13Rt0dJHtiTkkDEtqtl/48ETYZJRojOrmMAblpcVDVG4kUz4SOzb awF7JexkW9kpvjMz0RVTesibh+HTtKiYzfksPsB/nYGGMy5KwplTA0UMaGJCaVYhgqyk lkES3E/jiZtDHMiLkQ4yx7oHmN/giYL8xi9m52aOVM5uCuxBKgeo1kDvfn4dUbvmFYen 8fWZ41y2DSerza4mCvRkmiOI8f5KFVTQUSgJWQMO7xJcuIlJfnzqgsr9ScfxE+/1xlCD SXcImw2CKFHJhX2rDEalclDWxBHWiFkTOkYD6W7hdEmol1VE0kLgwPHohqGgvtdUOEBH S4OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hmqirtYd; 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 x13-20020a170902e04d00b0014f3a39ab28si8112134plx.494.2022.02.28.01.03.29; Mon, 28 Feb 2022 01:03:44 -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=@redhat.com header.s=mimecast20190719 header.b=hmqirtYd; 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 S233760AbiB1H5c (ORCPT + 99 others); Mon, 28 Feb 2022 02:57:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233754AbiB1H5a (ORCPT ); Mon, 28 Feb 2022 02:57:30 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 73E004614D for ; Sun, 27 Feb 2022 23:56:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646035011; 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: in-reply-to:in-reply-to:references:references; bh=WpShLimVwkmYIyb4Sx/D5oN6uinq/tsyvea/tNkwado=; b=hmqirtYdBVRLZK6hL66wYov+HGdAECXRI0i0nicYCNm7VNExW2+ILAfWH/JVOEXm4o1Tl8 WoXCpB/LOSSWL+2wB7gMfBAjlbDscl+sKrUCn8AXxUcqZ/1Kn7VQdaJLz4WnYJo6lgMPmH /kY2dqWymVJFAr4e6l1dA86Jz3ZTsRU= Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-652-bBqigvgqP6uNghWaKbW4PA-1; Mon, 28 Feb 2022 02:56:48 -0500 X-MC-Unique: bBqigvgqP6uNghWaKbW4PA-1 Received: by mail-lj1-f198.google.com with SMTP id x8-20020a2ea7c8000000b00246215e0fc3so5321235ljp.8 for ; Sun, 27 Feb 2022 23:56:48 -0800 (PST) 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=WpShLimVwkmYIyb4Sx/D5oN6uinq/tsyvea/tNkwado=; b=Q1aP5BkXvUwT7fHmxlHgTw1L7kibYYlvttOss81Ovr8IlaRmLsNq3jzNqQCV/STcat 0oEzE3/SqkIeNOCXIBXaf6JCC0SodQNv3bMM6pMDoH23NKBo7w7MSfaAkRVzrssKcrYo 66xDuf9pL5XXGTpLnNDj+s7U7nCQOVXqK4ugGPEMyke96Hccka7iIGL4iYIiXyjaIPdN 1sRnnWBh8Gst6QPnnJiZT1xyAxmp9gBcLmK1/zLe4foLOkQy/0b9J+rhKqZ1WxLC9TOi bjQNd4I4wUTGHaLfQJSiwIPxRPu6qSYeG21s8EiDOcARHzZk5UScznQun0uDGE+657Vd HpeA== X-Gm-Message-State: AOAM532wZ3hC803PBAfNE9dxGIM73qW+ZNGskLbEP+oYXdTKO0gwlRPz o9pDNY49qLWmrmyDQTVJStGji8nCem6CyvNlGOZDNn9ihB7sjx4+lORK4nPsJ0W/11V0O7IOobu aHZ2M3E5iFaEBoFvllinJSl7g/J9sKoYd3TvFyXdH X-Received: by 2002:a05:6512:3d08:b0:43f:8f45:d670 with SMTP id d8-20020a0565123d0800b0043f8f45d670mr12347887lfv.587.1646035007125; Sun, 27 Feb 2022 23:56:47 -0800 (PST) X-Received: by 2002:a05:6512:3d08:b0:43f:8f45:d670 with SMTP id d8-20020a0565123d0800b0043f8f45d670mr12347870lfv.587.1646035006582; Sun, 27 Feb 2022 23:56:46 -0800 (PST) MIME-Version: 1.0 References: <20220224103852.311369-1-baymaxhuang@gmail.com> <20220225090223.636877-1-baymaxhuang@gmail.com> In-Reply-To: From: Jason Wang Date: Mon, 28 Feb 2022 15:56:35 +0800 Message-ID: Subject: Re: [PATCH net-next v2] tun: support NAPI for packets received from batched XDP buffs To: Harold Huang 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=-4.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE 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 Mon, Feb 28, 2022 at 3:27 PM Harold Huang wrote: > > 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? It means msg_controllen is not used. But see below (adding sanity check seems to be better). > > 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? > I think the point is to make sure the caller doesn't send us too short msg_control. E.g the msg_controllen should be sizeof(tun_msg_ctl). So we probably need to check in both places. (And initialize msg_controllen is vhost_tx_batch()) Thanks