From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90D8CC433F5 for ; Mon, 28 Feb 2022 07:56:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233767AbiB1H5f (ORCPT ); Mon, 28 Feb 2022 02:57:35 -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-Google-Smtp-Source: ABdhPJzfhHYpKm5FgVHu1Kj0ut0Y1DimEmo470n7GHsQ68BLqiZLCnk3GS34aG6ImJhNzneAlmJSl+Y11Q6OzZguBG8= 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" 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