* [PATCH 0/2] afs: fix NULL alist dereference and address bitmask shifts
@ 2026-11-25 22:17 Elkin Cruz
2026-11-25 22:17 ` [PATCH 1/2] afs: Guard NULL alist on restart in afs_select_vlserver() Elkin Cruz
2026-11-25 22:17 ` [PATCH 2/2] afs: Use bitops for fileserver address bitmasks Elkin Cruz
0 siblings, 2 replies; 3+ messages in thread
From: Elkin Cruz @ 2026-11-25 22:17 UTC (permalink / raw)
To: David Howells, Marc Dionne
Cc: linux-afs, linux-kernel, llvm, irogers, Elkin Cruz
I am trying out new Clang static analysis checks for kernel bug
classes, and they flagged this code as possibly buggy. The findings
were triaged/fixed and commit descriptions were drafted with help of AI,
then checked against linux-next (not runtime-tested on hardware).
Thanks,
Elkin
Elkin Cruz (2):
afs: Guard NULL alist on restart in afs_select_vlserver()
afs: Use bitops for fileserver address bitmasks
fs/afs/rotate.c | 7 ++++---
fs/afs/vl_rotate.c | 15 +++++++++------
2 files changed, 13 insertions(+), 9 deletions(-)
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] afs: Guard NULL alist on restart in afs_select_vlserver()
2026-11-25 22:17 [PATCH 0/2] afs: fix NULL alist dereference and address bitmask shifts Elkin Cruz
@ 2026-11-25 22:17 ` Elkin Cruz
2026-11-25 22:17 ` [PATCH 2/2] afs: Use bitops for fileserver address bitmasks Elkin Cruz
1 sibling, 0 replies; 3+ messages in thread
From: Elkin Cruz @ 2026-11-25 22:17 UTC (permalink / raw)
To: David Howells, Marc Dionne
Cc: linux-afs, linux-kernel, llvm, irogers, Elkin Cruz, stable
In afs_select_vlserver(), restart_from_beginning: is reached from
no_more_servers: after pick_server:, where alist and vc->alist have
already been cleared to NULL at next_server:. If an earlier VL call
received a response (vc->call_responded == true) before failing with
-ECONNRESET (setting AFS_VL_CURSOR_RETRY), vc->call_responded remains
true until another server address is selected, causing
restart_from_beginning: to dereference a NULL vc->alist.
Guard the preferred-address update and afs_put_addrlist() at
restart_from_beginning: with if (alist), matching the failed: path.
Fixes: 98f9fda2057b ("afs: Fold the afs_addr_cursor struct in")
Cc: stable@vger.kernel.org
Signed-off-by: Elkin Cruz <elkin@google.com>
---
fs/afs/vl_rotate.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/fs/afs/vl_rotate.c b/fs/afs/vl_rotate.c
index 6ad9688d8f4b..8381d6a35d3e 100644
--- a/fs/afs/vl_rotate.c
+++ b/fs/afs/vl_rotate.c
@@ -171,12 +171,15 @@ bool afs_select_vlserver(struct afs_vl_cursor *vc)
restart_from_beginning:
_debug("restart");
- if (vc->call_responded &&
- vc->addr_index != vc->alist->preferred &&
- test_bit(alist->preferred, &vc->addr_tried))
- WRITE_ONCE(alist->preferred, vc->addr_index);
- afs_put_addrlist(alist, afs_alist_trace_put_vlrotate_restart);
- alist = vc->alist = NULL;
+ if (alist) {
+ if (vc->call_responded &&
+ vc->addr_index != alist->preferred &&
+ test_bit(alist->preferred, &vc->addr_tried))
+ WRITE_ONCE(alist->preferred, vc->addr_index);
+ afs_put_addrlist(alist, afs_alist_trace_put_vlrotate_restart);
+ vc->alist = NULL;
+ alist = NULL;
+ }
afs_put_vlserverlist(vc->cell->net, vc->server_list);
vc->server_list = NULL;
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] afs: Use bitops for fileserver address bitmasks
2026-11-25 22:17 [PATCH 0/2] afs: fix NULL alist dereference and address bitmask shifts Elkin Cruz
2026-11-25 22:17 ` [PATCH 1/2] afs: Guard NULL alist on restart in afs_select_vlserver() Elkin Cruz
@ 2026-11-25 22:17 ` Elkin Cruz
1 sibling, 0 replies; 3+ messages in thread
From: Elkin Cruz @ 2026-11-25 22:17 UTC (permalink / raw)
To: David Howells, Marc Dionne
Cc: linux-afs, linux-kernel, llvm, irogers, Elkin Cruz, stable
In afs_select_fileserver(), es->failed_set and set are unsigned long
bitmasks sized for AFS_MAX_ADDRESSES (BITS_PER_LONG). Testing bits via
32-bit signed shifts (1 << j and 1 << i) sign-extends at bit 31 and
invokes undefined behavior for bit positions >= 32 on 64-bit kernels.
Similarly, initializing s->untried_addrs via (1UL << nr_addrs) - 1
invokes shift undefined behavior when nr_addrs equals AFS_MAX_ADDRESSES.
Use test_bit() to inspect address bitmasks and GENMASK() to initialize
s->untried_addrs safely across all valid address counts.
Fixes: da0e01cc7079 ("afs: Fix fileserver rotation getting stuck")
Fixes: 495f2ae9e355 ("afs: Fix fileserver rotation")
Cc: stable@vger.kernel.org
Signed-off-by: Elkin Cruz <elkin@google.com>
---
fs/afs/rotate.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/fs/afs/rotate.c b/fs/afs/rotate.c
index 490b433e4395..a0d293ed2aa4 100644
--- a/fs/afs/rotate.c
+++ b/fs/afs/rotate.c
@@ -64,7 +64,8 @@ static bool afs_start_fs_iteration(struct afs_operation *op,
s->endpoint_state = afs_get_endpoint_state(estate,
afs_estate_trace_get_server_state);
s->probe_seq = estate->probe_seq;
- s->untried_addrs = (1UL << estate->addresses->nr_addrs) - 1;
+ s->untried_addrs = estate->addresses->nr_addrs ?
+ GENMASK(estate->addresses->nr_addrs - 1, 0) : 0;
init_waitqueue_entry(&s->probe_waiter, current);
afs_get_address_preferences(op->net, estate->addresses);
}
@@ -556,7 +557,7 @@ bool afs_select_fileserver(struct afs_operation *op)
afs_get_address_preferences_rcu(op->net, sal);
for (j = 0; j < sal->nr_addrs; j++) {
- if (es->failed_set & (1 << j))
+ if (test_bit(j, &es->failed_set))
continue;
if (!sal->addrs[j].peer)
continue;
@@ -617,7 +618,7 @@ bool afs_select_fileserver(struct afs_operation *op)
best_prio = -1;
addr_index = 0;
for (i = 0; i < alist->nr_addrs; i++) {
- if (!(set & (1 << i)))
+ if (!test_bit(i, &set))
continue;
if (alist->addrs[i].prio > best_prio) {
addr_index = i;
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-25 22:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 22:17 [PATCH 0/2] afs: fix NULL alist dereference and address bitmask shifts Elkin Cruz
2026-11-25 22:17 ` [PATCH 1/2] afs: Guard NULL alist on restart in afs_select_vlserver() Elkin Cruz
2026-11-25 22:17 ` [PATCH 2/2] afs: Use bitops for fileserver address bitmasks Elkin Cruz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox