From: Hillf Danton <hdanton@sina.com>
To: syzbot <syzbot+ec941d6e24f633a59172@syzkaller.appspotmail.com>
Cc: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com
Subject: Re: [syzbot] [net?] [bpf?] possible deadlock in sock_hash_delete_elem (2)
Date: Sat, 27 Apr 2024 16:15:36 +0800 [thread overview]
Message-ID: <20240427081536.3770-1-hdanton@sina.com> (raw)
In-Reply-To: <000000000000d0b87206170dd88f@google.com>
On Fri, 26 Apr 2024 23:08:19 -0700
> syzbot has found a reproducer for the following issue on:
>
> HEAD commit: b2ff42c6d3ab Merge tag 'for-netdev' of https://git.kernel...
> git tree: bpf
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=13c06aa0980000
#syz test https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git b2ff42c6d3ab
--- x/net/core/sock_map.c
+++ y/net/core/sock_map.c
@@ -928,6 +928,7 @@ static void sock_hash_delete_from_link(s
spin_unlock_bh(&bucket->lock);
}
+static DEFINE_PER_CPU(int, subclass);
static long sock_hash_delete_elem(struct bpf_map *map, void *key)
{
struct bpf_shtab *htab = container_of(map, struct bpf_shtab, map);
@@ -935,6 +936,7 @@ static long sock_hash_delete_elem(struct
struct bpf_shtab_bucket *bucket;
struct bpf_shtab_elem *elem;
int ret = -ENOENT;
+ int *class;
if (irqs_disabled())
return -EOPNOTSUPP; /* locks here are hardirq-unsafe */
@@ -942,7 +944,10 @@ static long sock_hash_delete_elem(struct
hash = sock_hash_bucket_hash(key, key_size);
bucket = sock_hash_select_bucket(htab, hash);
- spin_lock_bh(&bucket->lock);
+ local_bh_disable();
+ class = this_cpu_ptr(&subclass);
+ *class += 1;
+ spin_lock_nested(&bucket->lock, *class);
elem = sock_hash_lookup_elem_raw(&bucket->head, hash, key, key_size);
if (elem) {
hlist_del_rcu(&elem->node);
@@ -950,6 +955,7 @@ static long sock_hash_delete_elem(struct
sock_hash_free_elem(htab, elem);
ret = 0;
}
+ *class -= 1;
spin_unlock_bh(&bucket->lock);
return ret;
}
--
next prev parent reply other threads:[~2024-04-27 8:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-19 18:11 [syzbot] [bpf?] [net?] possible deadlock in sock_hash_delete_elem (2) syzbot
2024-04-27 6:08 ` [syzbot] [net?] [bpf?] " syzbot
2024-04-27 8:15 ` Hillf Danton [this message]
2024-04-27 8:45 ` syzbot
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=20240427081536.3770-1-hdanton@sina.com \
--to=hdanton@sina.com \
--cc=linux-kernel@vger.kernel.org \
--cc=syzbot+ec941d6e24f633a59172@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).