All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: kernel-hardening@lists.openwall.com
Cc: Kees Cook <keescook@chromium.org>,
	Michael Leibowitz <michael.leibowitz@intel.com>
Subject: [kernel-hardening] [PATCH 08/18] randstruct: Whitelist UNIXCB cast
Date: Thu,  6 Apr 2017 14:18:23 -0700	[thread overview]
Message-ID: <1491513513-84351-9-git-send-email-keescook@chromium.org> (raw)
In-Reply-To: <1491513513-84351-1-git-send-email-keescook@chromium.org>

This is another false positive in bad cast detection:

net/unix/af_unix.c: In function ‘unix_skb_scm_eq’:
net/unix/af_unix.c:1621:31: note: found mismatched rhs struct pointer types: ‘struct unix_skb_parms’ and ‘char’

  const struct unix_skb_parms *u = &UNIXCB(skb);
                               ^

UNIXCB is:

	#define UNIXCB(skb)     (*(struct unix_skb_parms *)&((skb)->cb))

And ->cb is:

	char                    cb[48] __aligned(8);

This is a rather crazy cast, but appears to be safe in the face of
randomization, so whitelist it in the plugin.

Signed-off-by: Kees Cook <keescook@chromium.org>
---
 scripts/gcc-plugins/randomize_layout_plugin.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/scripts/gcc-plugins/randomize_layout_plugin.c b/scripts/gcc-plugins/randomize_layout_plugin.c
index 63c654a00249..a2d7e933c33f 100644
--- a/scripts/gcc-plugins/randomize_layout_plugin.c
+++ b/scripts/gcc-plugins/randomize_layout_plugin.c
@@ -773,6 +773,15 @@ static bool type_name_eq(gimple stmt, const_tree type_tree, const char *wanted_n
 	case RECORD_TYPE:
 		type_name = TYPE_NAME_POINTER(type_tree);
 		break;
+	case INTEGER_TYPE:
+		if (TYPE_PRECISION(type_tree) == CHAR_TYPE_SIZE)
+			type_name = "char";
+		else {
+			inform(gimple_location(stmt), "found non-char INTEGER_TYPE cast comparison: %qT\n", type_tree);
+			debug_tree(type_tree);
+			return false;
+		}
+		break;
 	default:
 		inform(gimple_location(stmt), "unhandled cast comparison: %qT\n", type_tree);
 		debug_tree(type_tree);
@@ -864,7 +873,13 @@ static unsigned int find_bad_casts_execute(void)
 #ifndef __DEBUG_PLUGIN
 				if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
 #endif
-				inform(gimple_location(stmt), "found mismatched rhs struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
+				{
+					/* Whitelist unix_skb_parms via UNIXCB() */
+					if (whitelisted_cast(stmt, ptr_lhs_type, ptr_rhs_type, "unix_skb_parms", "char"))
+						continue;
+
+					inform(gimple_location(stmt), "found mismatched rhs struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
+				}
 				continue;
 			}
 
-- 
2.7.4

  parent reply	other threads:[~2017-04-06 21:18 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-06 21:18 [kernel-hardening] [PATCH 00/18] Introduce struct layout randomization plugin Kees Cook
2017-04-06 21:18 ` [kernel-hardening] [PATCH 01/18] gcc-plugins: Add the randstruct plugin Kees Cook
2017-04-12 22:12   ` [kernel-hardening] " Kees Cook
2017-04-17  5:30     ` Jessica Yu
2017-04-17 15:23       ` Kees Cook
2017-05-12  6:37         ` Loganaden Velvindron
2017-05-12 19:36           ` Kees Cook
2017-04-06 21:18 ` [kernel-hardening] [PATCH 02/18] compiler: Add __designated_init annotation Kees Cook
2017-04-06 21:18 ` [kernel-hardening] [PATCH 03/18] randstruct: Set designated_init attribute Kees Cook
2017-04-06 21:18 ` [kernel-hardening] [PATCH 04/18] randstruct: Differentiate bad cast warnings Kees Cook
2017-04-06 21:18 ` [kernel-hardening] [PATCH 05/18] af_unix: Use designated initializers Kees Cook
2017-04-06 21:18 ` [kernel-hardening] [PATCH 06/18] NFS: Avoid cross-structure casting Kees Cook
2017-04-06 21:18 ` [kernel-hardening] [PATCH 07/18] randstruct: Whitelist struct security_hook_heads cast Kees Cook
2017-04-06 21:18 ` Kees Cook [this message]
2017-04-06 21:18 ` [kernel-hardening] [PATCH 09/18] randstruct: Mark various structs for randomization Kees Cook
2017-04-06 21:18 ` [kernel-hardening] [PATCH 10/18] scsi/bfa: use designated initializers Kees Cook
2017-04-06 21:18 ` [kernel-hardening] [PATCH 11/18] scsi: qedi,qedf: Use " Kees Cook
2017-04-06 21:18 ` [kernel-hardening] [PATCH 12/18] ovl: " Kees Cook
2017-04-06 21:18 ` [kernel-hardening] [PATCH 13/18] randstruct: opt-out externally exposed function pointer structs Kees Cook
2017-04-06 21:18 ` [kernel-hardening] [PATCH 14/18] randstruct: Disable randomization of ACPICA structs Kees Cook
2017-04-06 21:18 ` [kernel-hardening] [PATCH 15/18] randstruct: Enable function pointer struct detection Kees Cook
2017-04-06 21:18 ` [kernel-hardening] [PATCH 16/18] task_struct: Allow randomized layout Kees Cook
2017-04-07 16:25   ` Rik van Riel
2017-04-07 20:43     ` Kees Cook
2017-04-06 21:18 ` [kernel-hardening] [PATCH 17/18] sgi-xp: Use designated initializers Kees Cook
2017-04-06 21:18 ` [kernel-hardening] [PATCH 18/18] ACPICA: " Kees Cook
2017-04-06 21:54 ` [kernel-hardening] [PATCH 00/18] Introduce struct layout randomization plugin James Morris
2017-04-06 22:32   ` Rik van Riel
2017-04-06 22:51     ` Kees Cook
2017-04-13 23:39 ` Laura Abbott
2017-04-15 18:50   ` Kees Cook
2017-04-18 17:15     ` Laura Abbott
2017-04-18 17:20       ` Kees Cook
2017-04-18 16:54 ` Laura Abbott

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=1491513513-84351-9-git-send-email-keescook@chromium.org \
    --to=keescook@chromium.org \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=michael.leibowitz@intel.com \
    /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 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.