[libvirt] [PATCH v4 02/25] qemusecuritymock: Fix bit arithmetic

Michal Privoznik posted 25 patches 6 years, 9 months ago
[libvirt] [PATCH v4 02/25] qemusecuritymock: Fix bit arithmetic
Posted by Michal Privoznik 6 years, 9 months ago
One of the functions of this mock is that it spoofs chown() and
stat() calls. But it is doing so in a clever way: it stores the
new owner on chown() and reports it on subsequent stat(). This is
done by using a 32bit unsigned integer where one half is used to
store uid the other is for gid. Later, when stat() is called the
integer is fetched and split into halves again. Well, my bit
operation skills are poor and the code I've written does not do
that properly.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 tests/qemusecuritymock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/qemusecuritymock.c b/tests/qemusecuritymock.c
index d170e5da8f..1ca8bd721f 100644
--- a/tests/qemusecuritymock.c
+++ b/tests/qemusecuritymock.c
@@ -226,7 +226,7 @@ int virFileRemoveXAttr(const char *path,
                 sb->st_gid = DEFAULT_GID; \
             } else { \
                 /* Known path. Set values passed to chown() earlier */ \
-                sb->st_uid = *val % 16; \
+                sb->st_uid = *val & 0xffff; \
                 sb->st_gid = *val >> 16; \
             } \
 \
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v4 02/25] qemusecuritymock: Fix bit arithmetic
Posted by Daniel P. Berrangé 6 years, 7 months ago
On Thu, Apr 25, 2019 at 10:19:38AM +0200, Michal Privoznik wrote:
> One of the functions of this mock is that it spoofs chown() and
> stat() calls. But it is doing so in a clever way: it stores the
> new owner on chown() and reports it on subsequent stat(). This is
> done by using a 32bit unsigned integer where one half is used to
> store uid the other is for gid. Later, when stat() is called the
> integer is fetched and split into halves again. Well, my bit
> operation skills are poor and the code I've written does not do
> that properly.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  tests/qemusecuritymock.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list