From: Abdullah <asharji1828@gmail.com>
To: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, skhan@linuxfoundation.org,
davem@davemloft.net, dsahern@kernel.org, edumazet@google.com,
horms@kernel.org, kuba@kernel.org, pabeni@redhat.com,
syzkaller-bugs@googlegroups.com, Abdullah <asharji1828@gmail.com>,
syzbot+5cfae50c0e5f2c500013@syzkaller.appspotmail.com
Subject: [PATCH v2] net: ipmr: Fix out-of-bounds access in mr_mfc_uses_dev()
Date: Wed, 29 Jan 2025 12:43:10 +0400 [thread overview]
Message-ID: <20250129084310.54397-1-asharji1828@gmail.com> (raw)
In-Reply-To: <20250129082601.51019-1-asharji1828@gmail.com>
The issue was reported by Syzbot as an out-of-bounds read:
UBSAN: array-index-out-of-bounds in net/ipv4/ipmr_base.c:289:10
Index -772737152 is out of range for type 'const struct vif_device[32]'
The problem occurs when the minvif/maxvif values in the mr_mfc struct
become invalid (possibly due to memory corruption or uninitialized values).
This patch fixes the issue by ensuring proper boundary checks and rcu_read
locking before accessing vif_table[] in mr_mfc_uses_dev().
Fixes: <COMMIT_HASH>
Reported-by: syzbot+5cfae50c0e5f2c500013@syzkaller.appspotmail.com
Signed-off-by: Abdullah <asharji1828@gmail.com>
---
net/ipv4/ipmr_base.c | 30 +++++++++++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
diff --git a/net/ipv4/ipmr_base.c b/net/ipv4/ipmr_base.c
index 03b6eee407a2..7c38d0cf41fc 100644
--- a/net/ipv4/ipmr_base.c
+++ b/net/ipv4/ipmr_base.c
@@ -280,9 +280,31 @@ static bool mr_mfc_uses_dev(const struct mr_table *mrt,
const struct mr_mfc *c,
const struct net_device *dev)
{
+ /**
+ * Helper function that checks if *dev is part of the OIL (Outgoing Interfaces List).
+ * @mrt: Is the multi-routing table.
+ * @c: Is the Multicast Forwarding Cache.
+ * @dev: The net device being checked.
+ *
+ * vif_dev: Pointer to the net device's struct.
+ * vif: Pointer to the actual device.
+ *
+ * OIL is a subset of mrt->vif_table[].
+ * minvif: Start index of OIL in vif_table[].
+ * maxvif: End index of OIL in vif_table[].
+ *
+ * Returns:
+ * - true if `dev` is part of the OIL.
+ * - false otherwise.
+ */
+
int ct;
+
+ int minvif = c->mfc_un.res.minvif, maxvif = c->mfc_un.res.maxvif;
+ if (minvif < 0 || maxvif > 32)
+ return false;
- for (ct = c->mfc_un.res.minvif; ct < c->mfc_un.res.maxvif; ct++) {
+ for (ct = minvif; ct < maxvif; ct++) {
const struct net_device *vif_dev;
const struct vif_device *vif;
@@ -309,7 +331,8 @@ int mr_table_dump(struct mr_table *mrt, struct sk_buff *skb,
if (filter->filter_set)
flags |= NLM_F_DUMP_FILTERED;
-
+
+ rcu_read_lock();
list_for_each_entry_rcu(mfc, &mrt->mfc_cache_list, list,
lockdep_rtnl_is_held()) {
if (e < s_e)
@@ -325,7 +348,8 @@ int mr_table_dump(struct mr_table *mrt, struct sk_buff *skb,
next_entry:
e++;
}
-
+ rcu_read_unlock();
+
spin_lock_bh(lock);
list_for_each_entry(mfc, &mrt->mfc_unres_queue, list) {
if (e < s_e)
--
2.43.0
next prev parent reply other threads:[~2025-01-29 8:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-21 18:09 [syzbot] [net?] UBSAN: array-index-out-of-bounds in mr_table_dump syzbot
2025-01-29 8:26 ` [PATCH] net: ipmr: Fix out-of-bounds access in mr_mfc_uses_dev() Abdullah
2025-01-29 8:43 ` Abdullah [this message]
2025-01-29 8:50 ` [PATCH v3] net: ipmr: Fix out-of-bounds access i mr_mfc_uses_dev() Abdullah
2025-01-30 0:56 ` Jakub Kicinski
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=20250129084310.54397-1-asharji1828@gmail.com \
--to=asharji1828@gmail.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=skhan@linuxfoundation.org \
--cc=syzbot+5cfae50c0e5f2c500013@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
/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).