From: Elkin Cruz <elkin@google.com>
To: David Howells <dhowells@redhat.com>,
Marc Dionne <marc.dionne@auristor.com>
Cc: linux-afs@lists.infradead.org, linux-kernel@vger.kernel.org,
llvm@lists.linux.dev, irogers@google.com,
Elkin Cruz <elkin@google.com>,
stable@vger.kernel.org
Subject: [PATCH 2/2] afs: Use bitops for fileserver address bitmasks
Date: Wed, 25 Nov 2026 22:17:30 +0000 [thread overview]
Message-ID: <20261125221730.1421806-3-elkin@google.com> (raw)
In-Reply-To: <20261125221730.1421806-1-elkin@google.com>
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
prev parent reply other threads:[~2026-11-25 22:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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=20261125221730.1421806-3-elkin@google.com \
--to=elkin@google.com \
--cc=dhowells@redhat.com \
--cc=irogers@google.com \
--cc=linux-afs@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=marc.dionne@auristor.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
all inboxes | Powered by JetHome®