From: Xiaomeng Tong <xiam0nd.tong@gmail.com>
To: agk@redhat.com
Cc: snitzer@redhat.com, dm-devel@redhat.com,
linux-kernel@vger.kernel.org,
Xiaomeng Tong <xiam0nd.tong@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH] md: fix missing check on list iterator
Date: Sun, 27 Mar 2022 13:37:42 +0800 [thread overview]
Message-ID: <20220327053742.2942-1-xiam0nd.tong@gmail.com> (raw)
The bug is here:
bypass_pg(m, pg, bypassed);
The list iterator 'pg' will point to a bogus position containing
HEAD if the list is empty or no element is found. This case must
be checked before any use of the iterator, otherwise it will lead
to a invalid memory access.
To fix this bug, run bypass_pg(m, pg, bypassed); and return 0
when found, otherwise return -EINVAL.
Cc: stable@vger.kernel.org
Fixes: ^1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com>
---
drivers/md/dm-mpath.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index f4719b65e5e3..6ba8f1133564 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -1496,12 +1496,13 @@ static int bypass_pg_num(struct multipath *m, const char *pgstr, bool bypassed)
}
list_for_each_entry(pg, &m->priority_groups, list) {
- if (!--pgnum)
- break;
+ if (!--pgnum) {
+ bypass_pg(m, pg, bypassed);
+ return 0;
+ }
}
- bypass_pg(m, pg, bypassed);
- return 0;
+ return -EINVAL;
}
/*
--
2.17.1
next reply other threads:[~2022-03-27 5:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-27 5:37 Xiaomeng Tong [this message]
2022-04-01 14:47 ` md: fix missing check on list iterator Mike Snitzer
2022-04-03 3:56 ` Xiaomeng Tong
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=20220327053742.2942-1-xiam0nd.tong@gmail.com \
--to=xiam0nd.tong@gmail.com \
--cc=agk@redhat.com \
--cc=dm-devel@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=snitzer@redhat.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;
as well as URLs for NNTP newsgroup(s).