Skip to contentSkip to conversation

authz: Add missing NULL checks

PATCH In review Kevin Wolf 3 participants 8 messages Nov 17, 2020

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

cover authz: Add missing NULL checks

While trying to write a QAPI schema for user creatable object types, I have to figure out whether properties are mandatory or options.

Turns out that some authz object types have properties that should be mandatory because the code assumes they are non-NULL, but we never check that they are actually given.

Kevin Wolf (2):
authz-pam: Check that 'service' property is set
authz-simple: Check that 'identity' property is set

 authz/pamacct.c |  6 ++++++
 authz/simple.c  | 14 ++++++++++++++
 2 files changed, 20 insertions(+)
Signature · 1 line
2.28.0
author
#1 lore raw

PATCH 1/2 authz-pam: Check that 'service' property is set

If the 'service' property is not set, we'll call pam_start() with a NULL pointer for the service name. This fails and leaves a message like this in the syslog:

qemu-storage-daemon[294015]: PAM pam_start: invalid argument: service == NULL

Make specifying the property mandatory and catch the error already during the creation of the object.

---
 authz/pamacct.c | 6 ++++++
 1 file changed, 6 insertions(+)
authz/pamacct.c +6 -0
index e67195f7be..c862d9ff39 100644
@@ -84,6 +84,12 @@ qauthz_pam_prop_get_service(Object *obj,
 static void
 qauthz_pam_complete(UserCreatable *uc, Error **errp)
 {
+    QAuthZPAM *pauthz = QAUTHZ_PAM(uc);
+
+    if (!pauthz->service) {
+        error_setg(errp, "The 'service' property must be set");
+        return;
+    }
 }
 
 
Signature · 1 line
2.28.0
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH for-5.2? 1/2] authz-pam: Check that 'service' property is set

Quoted 6 lines · Kevin Wolf

If the 'service' property is not set, we'll call pam_start() with a NULL pointer for the service name. This fails and leaves a message like this in the syslog:

qemu-storage-daemon[294015]: PAM pam_start: invalid argument: service == NULL

Quoted 7 lines

Make specifying the property mandatory and catch the error already during the creation of the object.

---
 authz/pamacct.c | 6 ++++++
 1 file changed, 6 insertions(+)

Regards,
Daniel

Signature · 3 lines
|: 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 :|
Reviewed-by on v1 1/2
#3 lore raw

Re: [PATCH for-5.2? 1/2] authz-pam: Check that 'service' property is set

In reply to Kevin Wolf
Quoted 6 lines · Kevin Wolf

If the 'service' property is not set, we'll call pam_start() with a NULL pointer for the service name. This fails and leaves a message like this in the syslog:

qemu-storage-daemon[294015]: PAM pam_start: invalid argument: service == NULL

Quoted 7 lines

Make specifying the property mandatory and catch the error already during the creation of the object.

---
 authz/pamacct.c | 6 ++++++
 1 file changed, 6 insertions(+)
author
#4 lore raw

PATCH 2/2 authz-simple: Check that 'identity' property is set

In reply to Kevin Wolf

If the 'identify' property is not set, we'll pass a NULL pointer to g_str_equal() and crash. Catch the error condition during the creation of the object.

---
 authz/simple.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
authz/simple.c +14 -0
index 18db0355f4..0597dcd8ea 100644
@@ -65,11 +65,25 @@ qauthz_simple_finalize(Object *obj)
 }
 
 
+static void
+qauthz_simple_complete(UserCreatable *uc, Error **errp)
+{
+    QAuthZSimple *sauthz = QAUTHZ_SIMPLE(uc);
+
+    if (!sauthz->identity) {
+        error_setg(errp, "The 'identity' property must be set");
+        return;
+    }
+}
+
+
 static void
 qauthz_simple_class_init(ObjectClass *oc, void *data)
 {
     QAuthZClass *authz = QAUTHZ_CLASS(oc);
+    UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);
 
+    ucc->complete = qauthz_simple_complete;
     authz->is_allowed = qauthz_simple_is_allowed;
 
     object_class_property_add_str(oc, "identity",
Signature · 1 line
2.28.0
Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH for-5.2? 2/2] authz-simple: Check that 'identity' property is set

Quoted 8 lines · Kevin Wolf

If the 'identify' property is not set, we'll pass a NULL pointer to g_str_equal() and crash. Catch the error condition during the creation of the object.

---
 authz/simple.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Regards,
Daniel

Signature · 3 lines
|: 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 :|
Reviewed-by on v1 2/2
#6 lore raw

Re: [PATCH for-5.2? 2/2] authz-simple: Check that 'identity' property is set

In reply to Kevin Wolf
Quoted 8 lines · Kevin Wolf

If the 'identify' property is not set, we'll pass a NULL pointer to g_str_equal() and crash. Catch the error condition during the creation of the object.

---
 authz/simple.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
#7 lore raw
In reply to Kevin Wolf
Quoted 6 lines · Kevin Wolf

While trying to write a QAPI schema for user creatable object types, I have to figure out whether properties are mandatory or options.

Turns out that some authz object types have properties that should be mandatory because the code assumes they are non-NULL, but we never check that they are actually given.

Hmm, avoiding manual code to check for mandatory options will be a nice plus point of using QAPI

Regards,
Daniel

Signature · 3 lines
|: 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 :|