Skip to contentSkip to conversation

sctp: prevent info leak in sctp_make_heartbeat()

PATCH In review Dan Carpenter 3 participants 4 messages Jun 29, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sctp: prevent info leak in sctp_make_heartbeat()

The "hbinfo" struct has a 4 byte hole at the end so we have to zero it out to prevent stack information from being disclosed.

Fixes fe59379b9ab7 ("sctp: do the basic send and recv for PLPMTUD probe")

---
Btw = {} is the newest way to initialize holes.

In the past we have debated whether = {} will *always* zero out struct holes and it wasn't clear from the C standard. But it turns out that "= {}" is not part of the standard but is instead a GCC extension and it does clear the holes. In GCC (not the C standard) then = {0}; is also supposed to initialize holes in there was a bug in one version where it didn't.

So that's nice, because adding memset()s to zero everywhere was ugly.

 net/sctp/sm_make_chunk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/sctp/sm_make_chunk.c +1 -1
index 587fb3cb88e2..3a290f620e96 100644
@@ -1162,7 +1162,7 @@ struct sctp_chunk *sctp_make_new_encap_port(const struct sctp_association *asoc,
 struct sctp_chunk *sctp_make_heartbeat(const struct sctp_association *asoc,
 				       const struct sctp_transport *transport)
 {
-	struct sctp_sender_hb_info hbinfo;
+	struct sctp_sender_hb_info hbinfo = {};
 	struct sctp_chunk *retval;
 
 	retval = sctp_make_control(asoc, SCTP_CID_HEARTBEAT, 0,
Signature · 1 line
2.30.2
#1 lore raw

Does that gcc extension work with all compilers, especially clang?

Dan Carpenter wrote on 29.06.21 10:19:

Quoted 33 lines

The "hbinfo" struct has a 4 byte hole at the end so we have to zero it out to prevent stack information from being disclosed.

Fixes fe59379b9ab7 ("sctp: do the basic send and recv for PLPMTUD probe")

---
Btw = {} is the newest way to initialize holes.

In the past we have debated whether = {} will *always* zero out struct holes and it wasn't clear from the C standard. But it turns out that "= {}" is not part of the standard but is instead a GCC extension and it does clear the holes. In GCC (not the C standard) then = {0}; is also supposed to initialize holes in there was a bug in one version where it didn't.

So that's nice, because adding memset()s to zero everywhere was ugly.

 net/sctp/sm_make_chunk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/sctp/sm_make_chunk.c +1 -1
index 587fb3cb88e2..3a290f620e96 100644
@@ -1162,7 +1162,7 @@ struct sctp_chunk *sctp_make_new_encap_port(const struct sctp_association *asoc,
 struct sctp_chunk *sctp_make_heartbeat(const struct sctp_association *asoc,
 				       const struct sctp_transport *transport)
 {
-	struct sctp_sender_hb_info hbinfo;
+	struct sctp_sender_hb_info hbinfo = {};
 	struct sctp_chunk *retval;
 
 	retval = sctp_make_control(asoc, SCTP_CID_HEARTBEAT, 0,
#3 lore raw
In reply to Andreas Fink
Quoted 6 lines

net/sctp/sm_make_chunk.c struct sctp_chunk *sctp_make_new_encap_port(const struct sctp_association *asoc, · line 1165

Quoted 2 lines
net/sctp/sm_make_chunk.c +1 -1
-	struct sctp_sender_hb_info hbinfo;
+	struct sctp_sender_hb_info hbinfo = {};

Does that gcc extension work with all compilers, especially clang?

Quoted 1 line

So that's nice, because adding memset()s to zero everywhere was ugly.

The 'real fun' (tm) starts when the bit pattern for the NULL pointer isn't 'all zeros'.
Using memset() is then broken - I suspect the compiler is expected to initialise pointers to the correct NULL pattern.

Not that I think anyone sane would consider trying to compile any 'normal' C code for such a system.

OTOH it is probably why clang is bleating about (int)((char *)0 + 4) being undefined behaviour.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)