Thread (10 messages) 10 messages, 5 authors, 2020-11-06

Re: [PATCH] crypto: af_alg - avoid undefined behavior accessing salg_name

flat view

From: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Date: 2020-10-26 23:05:35
Also in: linux-crypto, linux-hardening, lkml, stable

On Mon, Oct 26, 2020 at 04:21:48PM -0500, Gustavo A. R. Silva wrote:
quoted
+/*
+ * Linux v4.12 and later removed the 64-byte limit on salg_name[]; it's now an
+ * arbitrary-length field.  We had to keep the original struct above for source
+ * compatibility with existing userspace programs, though.  Use the new struct
+ * below if support for very long algorithm names is needed.  To do this,
+ * allocate 'sizeof(struct sockaddr_alg_new) + strlen(algname) + 1' bytes, and
+ * copy algname (including the null terminator) into salg_name.
+ */
+struct sockaddr_alg_new {
+	__u16	salg_family;
+	__u8	salg_type[14];
+	__u32	salg_feat;
+	__u32	salg_mask;
+	__u8	salg_name[];
+};
+
How something like this, instead:

 struct sockaddr_alg {
-	__u16	salg_family;
-	__u8	salg_type[14];
-	__u32	salg_feat;
-	__u32	salg_mask;
-	__u8	salg_name[64];
+	union {
+		struct {
+			__u16	salg_v1_family;
+			__u8	salg_v1_type[14];
+			__u32	salg_v1_feat;
+			__u32	salg_v1_mask;
+			__u8	salg_name[64];
+		};
+		struct {
+			__u16	salg_family;
+			__u8	salg_type[14];
+			__u32	salg_feat;
+			__u32	salg_mask;
+			__u8	salg_name_new[];
+		};
+	};
 };
Something similar to the following approach might work:

https://git.kernel.org/pub/scm/linux/kernel/git/gustavoars/linux.git/commit/?h=testing/uapi/gntalloc&id=db46c8aba41c436edb0b4ef2941bd7390b0e5d61

--
Gustavo
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help