Skip to contentSkip to conversation

ceph: fix off by one bugs in unsafe_request_wait()

PATCH Applied Dan Carpenter 2 participants 2 messages Sep 6, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ceph: fix off by one bugs in unsafe_request_wait()

The "> max" tests should be ">= max" to prevent an out of bounds access on the next lines.

Fixes e1a4541ec0b9 ("ceph: flush the mdlog before waiting on unsafe reqs")
---
 fs/ceph/caps.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ceph/caps.c +2 -2
index 26c5029629a4..ebbad9080422 100644
@@ -2260,7 +2260,7 @@ static int unsafe_request_wait(struct inode *inode)
 			list_for_each_entry(req, &ci->i_unsafe_dirops,
 					    r_unsafe_dir_item) {
 				s = req->r_session;
-				if (unlikely(s->s_mds > max)) {
+				if (unlikely(s->s_mds >= max)) {
 					spin_unlock(&ci->i_unsafe_lock);
 					goto retry;
 				}
@@ -2274,7 +2274,7 @@ static int unsafe_request_wait(struct inode *inode)
 			list_for_each_entry(req, &ci->i_unsafe_iops,
 					    r_unsafe_target_item) {
 				s = req->r_session;
-				if (unlikely(s->s_mds > max)) {
+				if (unlikely(s->s_mds >= max)) {
 					spin_unlock(&ci->i_unsafe_lock);
 					goto retry;
 				}
Signature · 1 line
2.20.1
maintainer Applied
#1 lore raw
Quoted 33 lines · Dan Carpenter

The "> max" tests should be ">= max" to prevent an out of bounds access on the next lines.

Fixes e1a4541ec0b9 ("ceph: flush the mdlog before waiting on unsafe reqs")
---
 fs/ceph/caps.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ceph/caps.c +2 -3
index 26c5029629a4..ebbad9080422 100644
@@ -2260,7 +2260,7 @@ static int unsafe_request_wait(struct inode *inode)
                        list_for_each_entry(req, &ci->i_unsafe_dirops,
                                            r_unsafe_dir_item) {
                                s = req->r_session;
-                               if (unlikely(s->s_mds > max)) {
+                               if (unlikely(s->s_mds >= max)) {
                                        spin_unlock(&ci->i_unsafe_lock);
                                        goto retry;
                                }
@@ -2274,7 +2274,7 @@ static int unsafe_request_wait(struct inode *inode)
                        list_for_each_entry(req, &ci->i_unsafe_iops,
                                            r_unsafe_target_item) {
                                s = req->r_session;
-                               if (unlikely(s->s_mds > max)) {
+                               if (unlikely(s->s_mds >= max)) {
                                        spin_unlock(&ci->i_unsafe_lock);
                                        goto retry;
                                }
--
Quoted 2 lines

2.20.1

Applied.

Thanks,

Ilya