All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] smatch_kernel_host_data: enable additional debug
@ 2022-05-18  8:07 Elena Reshetova
  2022-05-18  8:29 ` Dan Carpenter
  0 siblings, 1 reply; 5+ messages in thread
From: Elena Reshetova @ 2022-05-18  8:07 UTC (permalink / raw)
  To: smatch; +Cc: dan.carpenter, Elena Reshetova

This allows calling __smatch_host_rl(*val) from the
analysed code in the same way as __smatch_user_rl, but
for the data influenced by the host in confidential
computing threat model.

Code author: Dan Carpenter

Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
---
 check_debug.c | 35 +++++++++++++++++++++++++++++++++++
 check_debug.h |  1 +
 2 files changed, 36 insertions(+)

diff --git a/check_debug.c b/check_debug.c
index 8b7b845f..058585ac 100644
--- a/check_debug.c
+++ b/check_debug.c
@@ -215,6 +215,40 @@ static void match_user_rl(const char *fn, struct expression *expr, void *info)
 	free_string(name);
 }
 
+static void match_host_rl(const char *fn, struct expression *expr, void *info)
+{
+       struct expression *arg;
+       struct range_list *rl = NULL;
+       struct sm_state *sm;
+       bool capped = false;
+       bool new = false;
+       int host_id;
+       char *name;
+
+       host_id = id_from_name("register_kernel_host_data");
+       if (!host_id) {
+               sm_msg("no host id");
+               return;
+       }
+
+       arg = get_argument_from_call_expr(expr->args, 0);
+       name = expr_to_str(arg);
+
+       get_host_rl(arg, &rl);
+       if (rl)
+               capped = user_rl_capped(arg);
+       sm = get_sm_state_expr(host_id, arg);
+       if (sm && estate_new(sm->state))
+               new = true;
+
+       sm_msg("host rl: '%s' = '%s'%s %s sm='%s'", name, show_rl(rl),
+              capped ? " (capped)" : "",
+              new ? "(new)" : "(old)",
+              show_sm(sm));
+
+       free_string(name);
+}
+
 static void match_capped(const char *fn, struct expression *expr, void *info)
 {
 	struct expression *arg;
@@ -856,6 +890,7 @@ void check_debug(int id)
 	add_function_hook("__smatch_implied_min", &match_print_implied_min, NULL);
 	add_function_hook("__smatch_implied_max", &match_print_implied_max, NULL);
 	add_function_hook("__smatch_user_rl", &match_user_rl, NULL);
+	add_function_hook("__smatch_host_rl", &match_host_rl, NULL);
 	add_function_hook("__smatch_capped", &match_capped, NULL);
 	add_function_hook("__smatch_hard_max", &match_print_hard_max, NULL);
 	add_function_hook("__smatch_fuzzy_max", &match_print_fuzzy_max, NULL);
diff --git a/check_debug.h b/check_debug.h
index 683a565f..f2e1a879 100644
--- a/check_debug.h
+++ b/check_debug.h
@@ -13,6 +13,7 @@ static inline void __smatch_implied(long long val){}
 static inline void __smatch_implied_min(long long val){}
 static inline void __smatch_implied_max(long long val){}
 static inline void __smatch_user_rl(long long val){}
+static inline void __smatch_host_rl(long long val){}
 static inline void __smatch_capped(long long val){}
 
 static inline void __smatch_hard_max(long long val){}
-- 
2.25.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-06-28  8:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-18  8:07 [PATCH] smatch_kernel_host_data: enable additional debug Elena Reshetova
2022-05-18  8:29 ` Dan Carpenter
2022-05-18 10:03   ` Reshetova, Elena
2022-06-27 14:39     ` Dan Carpenter
2022-06-28  8:27       ` Reshetova, Elena

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.