Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1520400451-11475-2-git-send-email-me@tobin.cc>
Date: Wed,  7 Mar 2018 16:27:30 +1100
From: "Tobin C. Harding" <me@...in.cc>
To: Kernel Hardening <kernel-hardening@...ts.openwall.com>,
	Tycho Andersen <tycho@...ho.ws>
Cc: "Tobin C. Harding" <me@...in.cc>,
	Kees Cook <keescook@...omium.org>,
	Oleg Drokin <oleg.drokin@...el.com>,
	Andreas Dilger <andreas.dilger@...el.com>,
	James Simmons <jsimmons@...radead.org>,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Subject: [PATCH 1/2] vla: define new safe vla macros

We would like to get rid of VLAs all together but in the mean time we
can make their usage safer.

Define a macro to use for declaring a VLA.  Macro includes requested
'size' and 'max' allowed.  Macro allocates storage for an array
equivalent to

	int array[min(size, max)];

We also define a macro to check whether maximum size was reached.

Signed-off-by: Tobin C. Harding <me@...in.cc>
---
 include/linux/vla.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
 create mode 100644 include/linux/vla.h

diff --git a/include/linux/vla.h b/include/linux/vla.h
new file mode 100644
index 000000000000..ca0510d5e416
--- /dev/null
+++ b/include/linux/vla.h
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_VLA_H
+#define _LINUX_VLA_H
+
+#define VLA_DEFAULT_MAX 256
+
+/* evaluates 'size' and 'max' twice */
+#define VLA_SAFE(type, vla, size, max) type vla[(size) < (max) ? (size) : (max)]
+
+#define VLA_WARN_OVERSIZE(vla, size)				\
+do {								\
+	WARN(sizeof(vla) < size, "vla maximum exceeded\n");	\
+} while (0)
+
+#endif	/* _LINUX_VLA_H */
-- 
2.7.4

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.