From: Colin King <colin.king@canonical.com> To: Alasdair Kergon <agk@redhat.com>, Mike Snitzer <snitzer@redhat.com>, dm-devel@redhat.com, Joe Thornber <ejt@redhat.com> Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next] dm btree: Fix potential read of array with negative index i Date: Fri, 21 May 2021 11:52:36 +0100 [thread overview] Message-ID: <20210521105236.43860-1-colin.king@canonical.com> (raw) From: Colin Ian King <colin.king@canonical.com> The call to lower_bound can return -1 if the key is not found with the bsearch, leading to a negative index access into array node->keys[]. Ensure this cannot occur by checking for a negative index before reading from the array. Addresses-Coverity: ("Negative array index read") Fixes: d69e2e7e28bd ("dm btree: improve btree residency") Signed-off-by: Colin Ian King <colin.king@canonical.com> --- drivers/md/persistent-data/dm-btree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/md/persistent-data/dm-btree.c b/drivers/md/persistent-data/dm-btree.c index b8d21b6e2953..266deaea5eea 100644 --- a/drivers/md/persistent-data/dm-btree.c +++ b/drivers/md/persistent-data/dm-btree.c @@ -1048,7 +1048,7 @@ static bool contains_key(struct btree_node *node, uint64_t key) { int i = lower_bound(node, key); - if (le64_to_cpu(node->keys[i]) == key) + if (i >= 0 && le64_to_cpu(node->keys[i]) == key) return true; return false; -- 2.31.1
WARNING: multiple messages have this Message-ID (diff)
From: Colin King <colin.king@canonical.com> To: Alasdair Kergon <agk@redhat.com>, Mike Snitzer <snitzer@redhat.com>, dm-devel@redhat.com, Joe Thornber <ejt@redhat.com> Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [dm-devel] [PATCH][next] dm btree: Fix potential read of array with negative index i Date: Fri, 21 May 2021 11:52:36 +0100 [thread overview] Message-ID: <20210521105236.43860-1-colin.king@canonical.com> (raw) From: Colin Ian King <colin.king@canonical.com> The call to lower_bound can return -1 if the key is not found with the bsearch, leading to a negative index access into array node->keys[]. Ensure this cannot occur by checking for a negative index before reading from the array. Addresses-Coverity: ("Negative array index read") Fixes: d69e2e7e28bd ("dm btree: improve btree residency") Signed-off-by: Colin Ian King <colin.king@canonical.com> --- drivers/md/persistent-data/dm-btree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/md/persistent-data/dm-btree.c b/drivers/md/persistent-data/dm-btree.c index b8d21b6e2953..266deaea5eea 100644 --- a/drivers/md/persistent-data/dm-btree.c +++ b/drivers/md/persistent-data/dm-btree.c @@ -1048,7 +1048,7 @@ static bool contains_key(struct btree_node *node, uint64_t key) { int i = lower_bound(node, key); - if (le64_to_cpu(node->keys[i]) == key) + if (i >= 0 && le64_to_cpu(node->keys[i]) == key) return true; return false; -- 2.31.1 -- dm-devel mailing list dm-devel@redhat.com https://listman.redhat.com/mailman/listinfo/dm-devel
next reply other threads:[~2021-05-21 10:52 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-05-21 10:52 Colin King [this message] 2021-05-21 10:52 ` [dm-devel] [PATCH][next] dm btree: Fix potential read of array with negative index i Colin King 2021-05-25 9:58 ` Edward Thornber
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=20210521105236.43860-1-colin.king@canonical.com \ --to=colin.king@canonical.com \ --cc=agk@redhat.com \ --cc=dm-devel@redhat.com \ --cc=ejt@redhat.com \ --cc=kernel-janitors@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=snitzer@redhat.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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.