Linux-bcachefs Archive mirror
 help / color / mirror / Atom feed
From: Camila Alvarez <cam.alvarez.i@gmail.com>
To: Kent Overstreet <kent.overstreet@linux.dev>
Cc: Brian Foster <bfoster@redhat.com>,
	linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org,
	Camila Alvarez <cam.alvarez.i@gmail.com>,
	syzbot+249018ea545364f78d04@syzkaller.appspotmail.com
Subject: [PATCH] guard against unknown r->data_type in bch2_sb_dev_has_data()
Date: Tue, 14 May 2024 21:47:22 -0400	[thread overview]
Message-ID: <20240515014720.2482142-1-cam.alvarez.i@gmail.com> (raw)

Shift is perfomed only when the data type makes sense.

Fix a missing guard on r->data_type being known.

Reported-by: syzbot+249018ea545364f78d04@syzkaller.appspotmail.com
Signed-off-by: Camila Alvarez <cam.alvarez.i@gmail.com>
---
 fs/bcachefs/replicas.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/bcachefs/replicas.c b/fs/bcachefs/replicas.c
index 678b9c20e251..0fa91d0bf951 100644
--- a/fs/bcachefs/replicas.c
+++ b/fs/bcachefs/replicas.c
@@ -1006,14 +1006,14 @@ unsigned bch2_sb_dev_has_data(struct bch_sb *sb, unsigned dev)
 
 		for_each_replicas_entry(replicas, r)
 			for (i = 0; i < r->nr_devs; i++)
-				if (r->devs[i] == dev)
+				if (r->devs[i] == dev && r->data_type < BCH_DATA_NR)
 					data_has |= 1 << r->data_type;
 	} else if (replicas_v0) {
 		struct bch_replicas_entry_v0 *r;
 
 		for_each_replicas_entry_v0(replicas_v0, r)
 			for (i = 0; i < r->nr_devs; i++)
-				if (r->devs[i] == dev)
+				if (r->devs[i] == dev && r->data_type < BCH_DATA_NR)
 					data_has |= 1 << r->data_type;
 	}
 
-- 
2.34.1


             reply	other threads:[~2024-05-15  1:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-15  1:47 Camila Alvarez [this message]
2024-05-19 23:48 ` [PATCH] guard against unknown r->data_type in bch2_sb_dev_has_data() Kent Overstreet

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=20240515014720.2482142-1-cam.alvarez.i@gmail.com \
    --to=cam.alvarez.i@gmail.com \
    --cc=bfoster@redhat.com \
    --cc=kent.overstreet@linux.dev \
    --cc=linux-bcachefs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=syzbot+249018ea545364f78d04@syzkaller.appspotmail.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 read-only IMAP folder(s) and NNTP newsgroup(s).