All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH][next] dm btree: Fix potential read of array with negative index i
@ 2021-05-21 10:52 ` Colin King
  0 siblings, 0 replies; 3+ messages in thread
From: Colin King @ 2021-05-21 10:52 UTC (permalink / raw)
  To: Alasdair Kergon, Mike Snitzer, dm-devel, Joe Thornber
  Cc: kernel-janitors, linux-kernel

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [dm-devel] [PATCH][next] dm btree: Fix potential read of array with negative index i
@ 2021-05-21 10:52 ` Colin King
  0 siblings, 0 replies; 3+ messages in thread
From: Colin King @ 2021-05-21 10:52 UTC (permalink / raw)
  To: Alasdair Kergon, Mike Snitzer, dm-devel, Joe Thornber
  Cc: kernel-janitors, linux-kernel

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [dm-devel] [PATCH][next] dm btree: Fix potential read of array with negative index i
  2021-05-21 10:52 ` [dm-devel] " Colin King
  (?)
@ 2021-05-25  9:58 ` Edward Thornber
  -1 siblings, 0 replies; 3+ messages in thread
From: Edward Thornber @ 2021-05-25  9:58 UTC (permalink / raw)
  To: Colin King
  Cc: Mike Snitzer, kernel-janitors, linux-kernel, development,
	device-mapper, Joe Thornber, Alasdair Kergon


[-- Attachment #1.1: Type: text/plain, Size: 1202 bytes --]

ack

On Fri, May 21, 2021 at 11:52 AM Colin King <colin.king@canonical.com>
wrote:

> 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
>
>

[-- Attachment #1.2: Type: text/html, Size: 1780 bytes --]

[-- Attachment #2: Type: text/plain, Size: 97 bytes --]

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-05-26 11:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-21 10:52 [PATCH][next] dm btree: Fix potential read of array with negative index i Colin King
2021-05-21 10:52 ` [dm-devel] " Colin King
2021-05-25  9:58 ` Edward Thornber

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.