smatch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Elena Reshetova <elena.reshetova@intel.com>
To: smatch@vger.kernel.org
Cc: dan.carpenter@oracle.com, Elena Reshetova <elena.reshetova@intel.com>
Subject: [PATCH] check_spectre: Add a switch to optionally use host data
Date: Mon, 16 May 2022 11:55:47 +0300	[thread overview]
Message-ID: <20220516085547.1007627-1-elena.reshetova@intel.com> (raw)

check_spectre pattern can utilize smatch_kernel_host_data.c
to optionally search for potential spectre v1 gadgets in the
untrusted input provided for the host/VMM <-> VM guest attack
surface. This attack surface is important for confidential
cloud computing technologies where a VM guest does not trust
the host/VMM.

Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
---
 check_spectre.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/check_spectre.c b/check_spectre.c
index 16301a2e..009c7f0b 100644
--- a/check_spectre.c
+++ b/check_spectre.c
@@ -22,7 +22,13 @@ static int my_id;
 extern int second_half_id;
 extern void set_spectre_first_half(struct expression *expr);
 
+enum kernel_data_types {
+	USER_DATA_TYPE = 0,
+	HOST_DATA_TYPE = 1,
+};
+
 static int suppress_multiple = 1;
+static int analyzed_data_type = USER_DATA_TYPE;
 
 static int is_write(struct expression *expr)
 {
@@ -173,8 +179,19 @@ static void array_check(struct expression *expr)
 	}
 
 	offset = get_array_offset(expr);
-	if (!is_user_rl(offset))
-		return;
+	switch(analyzed_data_type) {
+		case USER_DATA_TYPE:
+			if (!is_user_rl(offset))
+				return;
+			break;
+		case HOST_DATA_TYPE:
+			if (!is_host_rl(offset))
+				return;
+			break;
+		default:
+			return;
+	}
+
 	if (is_nospec(offset))
 		return;
 
@@ -208,6 +225,8 @@ void check_spectre(int id)
 	my_id = id;
 
 	suppress_multiple = getenv("FULL_SPECTRE") == NULL;
+	if (getenv("ANALYZE_HOST_DATA"))
+		analyzed_data_type = HOST_DATA_TYPE;
 
 	if (option_project != PROJ_KERNEL)
 		return;
-- 
2.25.1

             reply	other threads:[~2022-05-16  8:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-16  8:55 Elena Reshetova [this message]
2022-05-16 12:54 ` [PATCH] check_spectre: Add a switch to optionally use host data Dan Carpenter
2022-05-16 13:39   ` Reshetova, Elena
2022-05-17 18:40     ` Dan Carpenter
2022-05-17 18:43       ` Reshetova, Elena

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220516085547.1007627-1-elena.reshetova@intel.com \
    --to=elena.reshetova@intel.com \
    --cc=dan.carpenter@oracle.com \
    --cc=smatch@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).