URL: https://github.com/SSSD/sssd/pull/743
Author: alexey-tikhonov
 Title: #743: lib/cifs_idmap_sss: fixed unaligned mem access
Action: opened

PR body:
"""
Fixed following warning:
```
lib/cifs_idmap_sss/cifs_idmap_sss.c: In function ‘sss_sid_to_id’:
lib/cifs_idmap_sss/cifs_idmap_sss.c:221:47: warning: taking address
of packed member of ‘struct cifs_uxid’ may result in an unaligned
pointer value [-Waddress-of-packed-member]

err = sss_nss_getidbysid(sid, (uint32_t *)&cuxid->id.uid, &id_type);
```

Actually there are two issues:
1) Packed `cifs_uxid::id.uid` may be unaligned thus generating run time
error on some architectures (as compiler complains);
2) In theory size of `uid_t` may be different than size of `uint32_t`
thus resulting in corruption of `cifs_uxid` content.

Proposed patch is not ideal due to `(uid_t)uid` cast but solves most
of issues with minimal effor. Proper solution would require patching of
`sss_nss_getidbysid()` and all underlying functions for no good reason.
"""

To pull the PR as Git branch:
git remote add ghsssd https://github.com/SSSD/sssd
git fetch ghsssd pull/743/head:pr743
git checkout pr743
From 0fe0948725341c3474ad64656df365e113acf67f Mon Sep 17 00:00:00 2001
From: Alexey Tikhonov <atikh...@redhat.com>
Date: Tue, 5 Feb 2019 16:34:31 +0100
Subject: [PATCH] lib/cifs_idmap_sss: fixed unaligned mem access
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Fixed following warning:
```
lib/cifs_idmap_sss/cifs_idmap_sss.c: In function ‘sss_sid_to_id’:
lib/cifs_idmap_sss/cifs_idmap_sss.c:221:47: warning: taking address
of packed member of ‘struct cifs_uxid’ may result in an unaligned
pointer value [-Waddress-of-packed-member]

err = sss_nss_getidbysid(sid, (uint32_t *)&cuxid->id.uid, &id_type);
```

Actually there are two issues:
1) Packed `cifs_uxid::id.uid` may be unaligned thus generating run time
error on some architectures (as compiler complains);
2) In theory size of `uid_t` may be different than size of `uint32_t`
thus resulting in corruption of `cifs_uxid` content.

Proposed patch is not ideal due to `(uid_t)uid` cast but solves most
of issues with minimal effor. Proper solution would require patching of
`sss_nss_getidbysid()` and all underlying functions for no good reason.
---
 src/lib/cifs_idmap_sss/cifs_idmap_sss.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/lib/cifs_idmap_sss/cifs_idmap_sss.c b/src/lib/cifs_idmap_sss/cifs_idmap_sss.c
index e7a0b83709..6434f4b677 100644
--- a/src/lib/cifs_idmap_sss/cifs_idmap_sss.c
+++ b/src/lib/cifs_idmap_sss/cifs_idmap_sss.c
@@ -217,12 +217,14 @@ static int sss_sid_to_id(struct sssd_ctx *ctx, const char *sid,
 {
     int err;
     enum sss_id_type id_type;
+    uint32_t uid;
 
-    err = sss_nss_getidbysid(sid, (uint32_t *)&cuxid->id.uid, &id_type);
+    err = sss_nss_getidbysid(sid, &uid, &id_type);
     if (err != 0)  {
         ctx_set_error(ctx, strerror(err));
         return -1;
     }
+    cuxid->id.uid = (uid_t)uid;
 
     switch (id_type) {
     case SSS_ID_TYPE_UID:
_______________________________________________
sssd-devel mailing list -- sssd-devel@lists.fedorahosted.org
To unsubscribe send an email to sssd-devel-le...@lists.fedorahosted.org
Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedorahosted.org/archives/list/sssd-devel@lists.fedorahosted.org

Reply via email to