From patchwork Wed May 1 22:09:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bethany Jamison X-Patchwork-Id: 1930358 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVB792tDgz1ydX for ; Thu, 2 May 2024 08:09:24 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1s2I8Y-00061d-Rc; Wed, 01 May 2024 22:09:14 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1s2I8X-00060a-AR for kernel-team@lists.ubuntu.com; Wed, 01 May 2024 22:09:13 +0000 Received: from mail-io1-f69.google.com (mail-io1-f69.google.com [209.85.166.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id DCC5A3F2D0 for ; Wed, 1 May 2024 22:09:11 +0000 (UTC) Received: by mail-io1-f69.google.com with SMTP id ca18e2360f4ac-7dec58efbfaso529831839f.3 for ; Wed, 01 May 2024 15:09:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714601350; x=1715206150; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2Vqo3Ip4+7mdRXQJlSfFiqNGPUYKVohoZW3o99kjmQk=; b=mfGo5GK9CTjmtgFNcS5yolPIZRSRgLucLUgf71nDfsrl/yFgk4K8rzs3xtWBOxkuAi OoxLwr9EWGWT7IzzL6xEG3k5TPJGoqpnRzyxf+bGyta/Hh/vZBjI3Jed/vHa3Lqh+1l1 ValZNL9AhQ+6cVXAYhGr8Y3tKJcuLlZC0Cxen71X6ZcaJ/nppTeSwm4arqqe4vkDCg9W +00n/80rvnj71D9EBMU7pr+xlcxomLNvRSYBEGGAZCkXf73p18YiuPw+hHPXDWT+mPXf HjpCo2cFGydoAuTMjuso71xgXOmXhyY9Nr0B0LVNsWhrDiex1lztB8JvEZK9vP1LBz77 dCwg== X-Gm-Message-State: AOJu0Yx2MVgPSeMt1TDKxULv7QvClpoiiCjtz45gv5k+OK7Gr0bA6btu sEmtxk/FpeWfFifu/bCMdvJGfry3FjUFmUla4Sekj3Oo0tNGdFKhQzMKkFiLU3ER5U+Dh+R/Bwt O4QOPFHEXdCVMMKtuOdWd0ehb7/zxz3gx9CfS31FU6M9Ut/olQh8jZd9e1qldDFfgZobKgKT40W mQSPWfj3ee2Q== X-Received: by 2002:a5e:c203:0:b0:7de:ced1:4380 with SMTP id v3-20020a5ec203000000b007deced14380mr4528967iop.13.1714601349909; Wed, 01 May 2024 15:09:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHqGuKOZWvTgqIDGtWrJ3ZDsWLHtlRwatIA/nPoxqyCYwgWX2SGRhbXBcWgAxJSfgFKerbz+w== X-Received: by 2002:a5e:c203:0:b0:7de:ced1:4380 with SMTP id v3-20020a5ec203000000b007deced14380mr4528947iop.13.1714601349493; Wed, 01 May 2024 15:09:09 -0700 (PDT) Received: from smtp.gmail.com (104-218-69-129.dynamic.lnk.ne.allofiber.net. [104.218.69.129]) by smtp.gmail.com with ESMTPSA id r11-20020a056638130b00b00487f8c82905sm1015729jad.13.2024.05.01.15.09.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 15:09:09 -0700 (PDT) From: Bethany Jamison To: kernel-team@lists.ubuntu.com Subject: [SRU][M][PATCH 1/1] net: veth: clear GRO when clearing XDP even when down Date: Wed, 1 May 2024 17:09:07 -0500 Message-Id: <20240501220907.23629-2-bethany.jamison@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240501220907.23629-1-bethany.jamison@canonical.com> References: <20240501220907.23629-1-bethany.jamison@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Jakub Kicinski [ Upstream commit fe9f801355f0b47668419f30f1fac1cf4539e736 ] veth sets NETIF_F_GRO automatically when XDP is enabled, because both features use the same NAPI machinery. The logic to clear NETIF_F_GRO sits in veth_disable_xdp() which is called both on ndo_stop and when XDP is turned off. To avoid the flag from being cleared when the device is brought down, the clearing is skipped when IFF_UP is not set. Bringing the device down should indeed not modify its features. Unfortunately, this means that clearing is also skipped when XDP is disabled _while_ the device is down. And there's nothing on the open path to bring the device features back into sync. IOW if user enables XDP, disables it and then brings the device up we'll end up with a stray GRO flag set but no NAPI instances. We don't depend on the GRO flag on the datapath, so the datapath won't crash. We will crash (or hang), however, next time features are sync'ed (either by user via ethtool or peer changing its config). The GRO flag will go away, and veth will try to disable the NAPIs. But the open path never created them since XDP was off, the GRO flag was a stray. If NAPI was initialized before we'll hang in napi_disable(). If it never was we'll crash trying to stop uninitialized hrtimer. Move the GRO flag updates to the XDP enable / disable paths, instead of mixing them with the ndo_open / ndo_close paths. Fixes: d3256efd8e8b ("veth: allow enabling NAPI even without XDP") Reported-by: Thomas Gleixner Reported-by: syzbot+039399a9b96297ddedca@syzkaller.appspotmail.com Signed-off-by: Jakub Kicinski Reviewed-by: Toke Høiland-Jørgensen Signed-off-by: David S. Miller Signed-off-by: Sasha Levin (cherry picked from commit 16edf51f33f52dff70ed455bc40a6cc443c04664 linux-6.6.y) CVE-2024-26803 Signed-off-by: Bethany Jamison --- drivers/net/veth.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/drivers/net/veth.c b/drivers/net/veth.c index 26123534f2d99..47affa69d6296 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -1201,14 +1201,6 @@ static int veth_enable_xdp(struct net_device *dev) veth_disable_xdp_range(dev, 0, dev->real_num_rx_queues, true); return err; } - - if (!veth_gro_requested(dev)) { - /* user-space did not require GRO, but adding XDP - * is supposed to get GRO working - */ - dev->features |= NETIF_F_GRO; - netdev_features_change(dev); - } } } @@ -1228,18 +1220,9 @@ static void veth_disable_xdp(struct net_device *dev) for (i = 0; i < dev->real_num_rx_queues; i++) rcu_assign_pointer(priv->rq[i].xdp_prog, NULL); - if (!netif_running(dev) || !veth_gro_requested(dev)) { + if (!netif_running(dev) || !veth_gro_requested(dev)) veth_napi_del(dev); - /* if user-space did not require GRO, since adding XDP - * enabled it, clear it now - */ - if (!veth_gro_requested(dev) && netif_running(dev)) { - dev->features &= ~NETIF_F_GRO; - netdev_features_change(dev); - } - } - veth_disable_xdp_range(dev, 0, dev->real_num_rx_queues, false); } @@ -1647,6 +1630,14 @@ static int veth_xdp_set(struct net_device *dev, struct bpf_prog *prog, } if (!old_prog) { + if (!veth_gro_requested(dev)) { + /* user-space did not require GRO, but adding + * XDP is supposed to get GRO working + */ + dev->features |= NETIF_F_GRO; + netdev_features_change(dev); + } + peer->hw_features &= ~NETIF_F_GSO_SOFTWARE; peer->max_mtu = max_mtu; } @@ -1662,6 +1653,14 @@ static int veth_xdp_set(struct net_device *dev, struct bpf_prog *prog, if (dev->flags & IFF_UP) veth_disable_xdp(dev); + /* if user-space did not require GRO, since adding XDP + * enabled it, clear it now + */ + if (!veth_gro_requested(dev)) { + dev->features &= ~NETIF_F_GRO; + netdev_features_change(dev); + } + if (peer) { peer->hw_features |= NETIF_F_GSO_SOFTWARE; peer->max_mtu = ETH_MAX_MTU;