[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2] xsm/flask: adjust print messages to use %pd


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: "Daniel P. Smith" <dpsmith@xxxxxxxxxxxxxxxxxxxx>
  • Date: Wed, 21 Sep 2022 11:16:14 -0400
  • Arc-authentication-results: i=1; mx.zohomail.com; dkim=pass header.i=apertussolutions.com; spf=pass smtp.mailfrom=dpsmith@xxxxxxxxxxxxxxxxxxxx; dmarc=pass header.from=<dpsmith@xxxxxxxxxxxxxxxxxxxx>
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1663773385; h=Content-Transfer-Encoding:Cc:Date:From:MIME-Version:Message-ID:Subject:To; bh=NDoK6DyexoYdIaow3/4JAZN25fIJLHqdzOzXM8IXl3o=; b=HmwmuD7LiUoYSwCAu+DPgrydrL0+BxUdcyLJOeLhRzbsCT/6VyLxC16Wkn+6UBT+tl4F8rKvFByklodGbvnvT6clIv7hQxE0KU0/OcAHwzec88O6D9fuFvDNHHyeUcyOMDCWP53a/8lTYmJb/xVMkFI5R0jX193oDjsmSt7fWHU=
  • Arc-seal: i=1; a=rsa-sha256; t=1663773385; cv=none; d=zohomail.com; s=zohoarc; b=BVT42Uz5FnrFyisddM56XrDdGxcxVksqaY9rB8dwvjn5MtzCun4/ujOSWqlhcCm6QA9UpUkYNBatnC4P4CILGX3qsiLDLeI15elFyWuLwkbJ0/80BquEQzgZPurf80VIseotRPkNcqkinCjlw2vlmjed1A2jK0s69blyupctJWk=
  • Cc: "Daniel P. Smith" <dpsmith@xxxxxxxxxxxxxxxxxxxx>, jandryuk@xxxxxxxxx, Henry Wang <Henry.Wang@xxxxxxx>
  • Delivery-date: Wed, 21 Sep 2022 15:16:47 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Print messages from flask use an inconsistent format when printing the domain
id. When referencing system domains, the domain id is printed which is not
immediately identifiable. The %pd conversion specifier provides a consistent
and clear way to format for the domain id. In addition this will assist in
aligning FLASK with current hypervisor code practices.

While addressing the domain id formating, two relatd issues were addressed.
The first being that avc_printk() was not applying any conversion specifier
validation. To address this, the printf annotation was added to avc_printk() to
help ensure the correct types are passed to each conversion specifier. The 
second
was concern that source and target domains were being appropriately reported for
an AVC. This was addressed by simplifying the conditional logic.

Signed-off-by: Daniel P. Smith <dpsmith@xxxxxxxxxxxxxxxxxxxx>
Reviewed-by: Henry Wang <Henry.Wang@xxxxxxx>
---

Changes in v2:
 - Grossly simplified the conditional logic for printing source/target domids
   to address concerns raised by Jan.

 xen/xsm/flask/avc.c   | 16 ++++++++--------
 xen/xsm/flask/hooks.c |  3 +--
 2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/xen/xsm/flask/avc.c b/xen/xsm/flask/avc.c
index 4a75ec97e2..3d39e55cae 100644
--- a/xen/xsm/flask/avc.c
+++ b/xen/xsm/flask/avc.c
@@ -113,7 +113,8 @@ struct avc_dump_buf {
     u32 free;
 };
 
-static void avc_printk(struct avc_dump_buf *buf, const char *fmt, ...)
+static void __attribute__ ((format (printf, 2, 3)))
+    avc_printk(struct avc_dump_buf *buf, const char *fmt, ...)
 {
     int i;
     va_list args;
@@ -565,15 +566,14 @@ void avc_audit(u32 ssid, u32 tsid, u16 tclass, u32 
requested,
 
     if ( a && (a->sdom || a->tdom) )
     {
-        if ( a->sdom && a->tdom && a->sdom != a->tdom )
-            avc_printk(&buf, "domid=%d target=%d ", a->sdom->domain_id, 
a->tdom->domain_id);
-        else if ( a->sdom )
-            avc_printk(&buf, "domid=%d ", a->sdom->domain_id);
-        else
-            avc_printk(&buf, "target=%d ", a->tdom->domain_id);
+        if ( a->sdom )
+            avc_printk(&buf, "source=%pd ", a->sdom);
+        if ( a->tdom && a->tdom != a->sdom )
+            avc_printk(&buf, "target=%pd ", a->tdom);
     }
     else if ( cdom )
-        avc_printk(&buf, "domid=%d ", cdom->domain_id);
+        avc_printk(&buf, "current=%pd ", cdom);
+
     switch ( a ? a->type : 0 ) {
     case AVC_AUDIT_DATA_DEV:
         avc_printk(&buf, "device=%#lx ", a->device);
diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c
index 8bd56644ef..a79281bdb0 100644
--- a/xen/xsm/flask/hooks.c
+++ b/xen/xsm/flask/hooks.c
@@ -281,8 +281,7 @@ static int cf_check flask_evtchn_interdomain(
     rc = security_transition_sid(sid1, sid2, SECCLASS_EVENT, &newsid);
     if ( rc )
     {
-        printk("security_transition_sid failed, rc=%d, Dom%d\n",
-               -rc, d2->domain_id);
+        printk("security_transition_sid failed, rc=%d, %pd\n", -rc, d2);
         return rc;
     }
 
-- 
2.20.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.