From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Joe Damato <jdamato@fastly.com>, Jakub Kicinski <kuba@kernel.org>,
Eric Dumazet <edumazet@google.com>,
Sasha Levin <sashal@kernel.org>,
davem@davemloft.net, pabeni@redhat.com, corbet@lwn.net,
leitao@debian.org, johannes.berg@intel.com,
jamie.bainbridge@gmail.com, netdev@vger.kernel.org,
linux-doc@vger.kernel.org
Subject: [PATCH AUTOSEL 6.11 079/244] net: napi: Prevent overflow of napi_defer_hard_irqs
Date: Wed, 25 Sep 2024 07:25:00 -0400 [thread overview]
Message-ID: <20240925113641.1297102-79-sashal@kernel.org> (raw)
In-Reply-To: <20240925113641.1297102-1-sashal@kernel.org>
From: Joe Damato <jdamato@fastly.com>
[ Upstream commit 08062af0a52107a243f7608fd972edb54ca5b7f8 ]
In commit 6f8b12d661d0 ("net: napi: add hard irqs deferral feature")
napi_defer_irqs was added to net_device and napi_defer_irqs_count was
added to napi_struct, both as type int.
This value never goes below zero, so there is not reason for it to be a
signed int. Change the type for both from int to u32, and add an
overflow check to sysfs to limit the value to S32_MAX.
The limit of S32_MAX was chosen because the practical limit before this
patch was S32_MAX (anything larger was an overflow) and thus there are
no behavioral changes introduced. If the extra bit is needed in the
future, the limit can be raised.
Before this patch:
$ sudo bash -c 'echo 2147483649 > /sys/class/net/eth4/napi_defer_hard_irqs'
$ cat /sys/class/net/eth4/napi_defer_hard_irqs
-2147483647
After this patch:
$ sudo bash -c 'echo 2147483649 > /sys/class/net/eth4/napi_defer_hard_irqs'
bash: line 0: echo: write error: Numerical result out of range
Similarly, /sys/class/net/XXXXX/tx_queue_len is defined as unsigned:
include/linux/netdevice.h: unsigned int tx_queue_len;
And has an overflow check:
dev_change_tx_queue_len(..., unsigned long new_len):
if (new_len != (unsigned int)new_len)
return -ERANGE;
Suggested-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Joe Damato <jdamato@fastly.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20240904153431.307932-1-jdamato@fastly.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
Documentation/networking/net_cachelines/net_device.rst | 2 +-
include/linux/netdevice.h | 4 ++--
net/core/net-sysfs.c | 6 +++++-
3 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/Documentation/networking/net_cachelines/net_device.rst b/Documentation/networking/net_cachelines/net_device.rst
index 70c4fb9d4e5ce..d68f37f5b1f82 100644
--- a/Documentation/networking/net_cachelines/net_device.rst
+++ b/Documentation/networking/net_cachelines/net_device.rst
@@ -98,7 +98,7 @@ unsigned_int num_rx_queues
unsigned_int real_num_rx_queues - read_mostly get_rps_cpu
struct_bpf_prog* xdp_prog - read_mostly netif_elide_gro()
unsigned_long gro_flush_timeout - read_mostly napi_complete_done
-int napi_defer_hard_irqs - read_mostly napi_complete_done
+u32 napi_defer_hard_irqs - read_mostly napi_complete_done
unsigned_int gro_max_size - read_mostly skb_gro_receive
unsigned_int gro_ipv4_max_size - read_mostly skb_gro_receive
rx_handler_func_t* rx_handler read_mostly - __netif_receive_skb_core
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 607009150b5fa..39eafd2e2368a 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -356,7 +356,7 @@ struct napi_struct {
unsigned long state;
int weight;
- int defer_hard_irqs_count;
+ u32 defer_hard_irqs_count;
unsigned long gro_bitmask;
int (*poll)(struct napi_struct *, int);
#ifdef CONFIG_NETPOLL
@@ -2091,7 +2091,7 @@ struct net_device {
unsigned int real_num_rx_queues;
struct netdev_rx_queue *_rx;
unsigned long gro_flush_timeout;
- int napi_defer_hard_irqs;
+ u32 napi_defer_hard_irqs;
unsigned int gro_max_size;
unsigned int gro_ipv4_max_size;
rx_handler_func_t __rcu *rx_handler;
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 291fdf4a328b3..93dd5d5436849 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -32,6 +32,7 @@
#ifdef CONFIG_SYSFS
static const char fmt_hex[] = "%#x\n";
static const char fmt_dec[] = "%d\n";
+static const char fmt_uint[] = "%u\n";
static const char fmt_ulong[] = "%lu\n";
static const char fmt_u64[] = "%llu\n";
@@ -425,6 +426,9 @@ NETDEVICE_SHOW_RW(gro_flush_timeout, fmt_ulong);
static int change_napi_defer_hard_irqs(struct net_device *dev, unsigned long val)
{
+ if (val > S32_MAX)
+ return -ERANGE;
+
WRITE_ONCE(dev->napi_defer_hard_irqs, val);
return 0;
}
@@ -438,7 +442,7 @@ static ssize_t napi_defer_hard_irqs_store(struct device *dev,
return netdev_store(dev, attr, buf, len, change_napi_defer_hard_irqs);
}
-NETDEVICE_SHOW_RW(napi_defer_hard_irqs, fmt_dec);
+NETDEVICE_SHOW_RW(napi_defer_hard_irqs, fmt_uint);
static ssize_t ifalias_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t len)
--
2.43.0
next prev parent reply other threads:[~2024-09-25 11:39 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-25 11:23 [PATCH AUTOSEL 6.11 001/244] l2tp: prevent possible tunnel refcount underflow Sasha Levin
2024-09-25 11:23 ` [PATCH AUTOSEL 6.11 009/244] ice: Adjust over allocation of memory in ice_sched_add_root_node() and ice_sched_add_node() Sasha Levin
2024-09-25 11:23 ` [PATCH AUTOSEL 6.11 012/244] wifi: cfg80211: Set correct chandef when starting CAC Sasha Levin
2024-09-25 11:23 ` [PATCH AUTOSEL 6.11 013/244] net/xen-netback: prevent UAF in xenvif_flush_hash() Sasha Levin
2024-09-25 11:23 ` [PATCH AUTOSEL 6.11 014/244] net: hisilicon: hip04: fix OF node leak in probe() Sasha Levin
2024-09-25 11:23 ` [PATCH AUTOSEL 6.11 015/244] net: hisilicon: hns_dsaf_mac: fix OF node leak in hns_mac_get_info() Sasha Levin
2024-09-25 11:23 ` [PATCH AUTOSEL 6.11 016/244] net: hisilicon: hns_mdio: fix OF node leak in probe() Sasha Levin
2024-09-25 11:24 ` [PATCH AUTOSEL 6.11 022/244] e1000e: avoid failing the system during pm_suspend Sasha Levin
2024-09-25 11:24 ` [PATCH AUTOSEL 6.11 025/244] net: sched: consistently use rcu_replace_pointer() in taprio_change() Sasha Levin
2024-09-25 11:24 ` [PATCH AUTOSEL 6.11 036/244] l2tp: don't use tunnel socket sk_user_data in ppp procfs output Sasha Levin
2024-09-25 11:24 ` [PATCH AUTOSEL 6.11 037/244] l2tp: free sessions using rcu Sasha Levin
2024-09-25 11:24 ` [PATCH AUTOSEL 6.11 038/244] l2tp: use rcu list add/del when updating lists Sasha Levin
2024-09-25 11:24 ` [PATCH AUTOSEL 6.11 042/244] tipc: guard against string buffer overrun Sasha Levin
2024-09-25 11:24 ` [PATCH AUTOSEL 6.11 043/244] net: skbuff: sprinkle more __GFP_NOWARN on ingress allocs Sasha Levin
2024-09-25 11:24 ` [PATCH AUTOSEL 6.11 044/244] net: mvpp2: Increase size of queue_name buffer Sasha Levin
2024-09-25 11:24 ` [PATCH AUTOSEL 6.11 045/244] bnxt_en: Extend maximum length of version string by 1 byte Sasha Levin
2024-09-25 11:24 ` [PATCH AUTOSEL 6.11 046/244] ipv4: Check !in_dev earlier for ioctl(SIOCSIFADDR) Sasha Levin
2024-09-25 11:24 ` [PATCH AUTOSEL 6.11 048/244] netfilter: nf_tables: do not remove elements if set backend implements .abort Sasha Levin
2024-09-25 11:24 ` [PATCH AUTOSEL 6.11 049/244] netfilter: nf_tables: don't initialize registers in nft_do_chain() Sasha Levin
2024-09-25 11:58 ` Pablo Neira Ayuso
2024-09-25 12:17 ` Pablo Neira Ayuso
2024-09-25 12:20 ` Florian Westphal
2024-10-06 0:28 ` Sasha Levin
2024-09-25 11:24 ` [PATCH AUTOSEL 6.11 050/244] ipv4: Mask upper DSCP bits and ECN bits in NETLINK_FIB_LOOKUP family Sasha Levin
2024-09-25 11:24 ` [PATCH AUTOSEL 6.11 054/244] net: atlantic: Avoid warning about potential string truncation Sasha Levin
2024-09-25 11:24 ` [PATCH AUTOSEL 6.11 056/244] netpoll: Ensure clean state on setup failures Sasha Levin
2024-09-25 11:24 ` [PATCH AUTOSEL 6.11 057/244] tcp: avoid reusing FIN_WAIT2 when trying to find port in connect() process Sasha Levin
2024-09-25 11:24 ` [PATCH AUTOSEL 6.11 062/244] wifi: mac80211: fix RCU list iterations Sasha Levin
2024-09-25 11:24 ` [PATCH AUTOSEL 6.11 068/244] can: netlink: avoid call to do_set_data_bittiming callback with stale can_priv::ctrlmode Sasha Levin
2024-09-25 11:24 ` [PATCH AUTOSEL 6.11 069/244] netdev-genl: Set extack and fix error on napi-get Sasha Levin
2024-09-25 11:24 ` [PATCH AUTOSEL 6.11 075/244] net: phy: Check for read errors in SIOCGMIIREG Sasha Levin
2024-09-25 11:25 ` Sasha Levin [this message]
2024-09-25 11:25 ` [PATCH AUTOSEL 6.11 084/244] net: tls: wait for async completion on last message Sasha Levin
2024-09-25 11:25 ` [PATCH AUTOSEL 6.11 087/244] nfp: Use IRQF_NO_AUTOEN flag in request_irq() Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240925113641.1297102-79-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jamie.bainbridge@gmail.com \
--cc=jdamato@fastly.com \
--cc=johannes.berg@intel.com \
--cc=kuba@kernel.org \
--cc=leitao@debian.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).