git: 503ac069aa4c - stable/13 - libkvm: fix kvm_walk_pages

From: Ed Maste <emaste_at_FreeBSD.org>
Date: Thu, 17 Feb 2022 01:18:56 UTC
The branch stable/13 has been updated by emaste:

URL: https://cgit.FreeBSD.org/src/commit/?id=503ac069aa4cabd8fb3aeaec705c5c926e39d452

commit 503ac069aa4cabd8fb3aeaec705c5c926e39d452
Author:     Bora Özarslan <borako.ozarslan@gmail.com>
AuthorDate: 2021-11-25 19:09:26 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2022-02-17 01:18:32 +0000

    libkvm: fix kvm_walk_pages
    
    Correct bitmap operations in _kvm_bitmap_next.
    
    Reviewed by:    jhb
    MFC after:      2 weeks
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D19183
    
    (cherry picked from commit 08055452cbf24a3cea48cb4f665bab78d89b7a39)
---
 lib/libkvm/kvm_private.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/libkvm/kvm_private.c b/lib/libkvm/kvm_private.c
index d853d1643101..a45f66caf2fe 100644
--- a/lib/libkvm/kvm_private.c
+++ b/lib/libkvm/kvm_private.c
@@ -792,8 +792,8 @@ _kvm_bitmap_next(struct kvm_bitmap *bm, u_long *idx)
 
 	/* Find the next valid idx. */
 	for (; *idx < first_invalid; (*idx)++) {
-		unsigned int mask = *idx % CHAR_BIT;
-		if ((bm->map[*idx * CHAR_BIT] & mask) == 0)
+		unsigned int mask = 1U << (*idx % CHAR_BIT);
+		if ((bm->map[*idx / CHAR_BIT] & mask) != 0)
 			break;
 	}