Skip to contentSkip to conversation

scpt: Allow struct sctp_event_subscribe to grow without breaking binaries

PATCH Applied Thomas Graf 3 participants 4 messages Apr 4, 2012

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

PATCH 1/1 scpt: Allow struct sctp_event_subscribe to grow without breaking binaries

getsockopt(..., SCTP_EVENTS, ...) performs a length check and returns an error if the user provides less bytes than the size of struct sctp_event_subscribe.

Struct sctp_event_subscribe needs to be extended by an u8 for every new event or notification type that is added.

This obviously makes getsockopt fail for binaries that are compiled against an older versions of <net/sctp/user.h> which do not contain all event types.

This patch changes getsockopt behaviour to no longer return an error if not enough bytes are being provided by the user. Instead, it returns as much of sctp_event_subscribe as fits into the provided buffer.

This leads to the new behavior that users see what they have been aware of at compile time.

The setsockopt(..., SCTP_EVENTS, ...) API is already behaving like this.

---
 net/sctp/socket.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
net/sctp/socket.c +3 -2
index 06b42b7..92ba71d 100644
@@ -4133,9 +4133,10 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
 				  int __user *optlen)
 {
-	if (len < sizeof(struct sctp_event_subscribe))
+	if (len <= 0)
 		return -EINVAL;
-	len = sizeof(struct sctp_event_subscribe);
+	if (len > sizeof(struct sctp_event_subscribe))
+		len = sizeof(struct sctp_event_subscribe);
 	if (put_user(len, optlen))
 		return -EFAULT;
 	if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
Acked-by on v1 1/1
#1 lore raw
Quoted 15 lines · Thomas Graf

getsockopt(..., SCTP_EVENTS, ...) performs a length check and returns an error if the user provides less bytes than the size of struct sctp_event_subscribe.

Struct sctp_event_subscribe needs to be extended by an u8 for every new event or notification type that is added.

This obviously makes getsockopt fail for binaries that are compiled against an older versions of <net/sctp/user.h> which do not contain all event types.

This patch changes getsockopt behaviour to no longer return an error if not enough bytes are being provided by the user. Instead, it returns as much of sctp_event_subscribe as fits into the provided buffer.

Quoted 6 lines

This leads to the new behavior that users see what they have been aware of at compile time.

The setsockopt(..., SCTP_EVENTS, ...) API is already behaving like this.

-vlad

Quoted 22 lines
---
 net/sctp/socket.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
net/sctp/socket.c +3 -2
index 06b42b7..92ba71d 100644
@@ -4133,9 +4133,10 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
 				  int __user *optlen)
 {
-	if (len < sizeof(struct sctp_event_subscribe))
+	if (len <= 0)
 		return -EINVAL;
-	len = sizeof(struct sctp_event_subscribe);
+	if (len > sizeof(struct sctp_event_subscribe))
+		len = sizeof(struct sctp_event_subscribe);
 	if (put_user(len, optlen))
 		return -EFAULT;
 	if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
maintainer Applied
#2 lore raw

From: Vladislav Yasevich <[email protected]>
Date: Wed, 04 Apr 2012 09:52:04 -0400

Quoted 16 lines · Thomas Graf
Quoted 15 lines

getsockopt(..., SCTP_EVENTS, ...) performs a length check and returns an error if the user provides less bytes than the size of struct sctp_event_subscribe.

Struct sctp_event_subscribe needs to be extended by an u8 for every new event or notification type that is added.

This obviously makes getsockopt fail for binaries that are compiled against an older versions of <net/sctp/user.h> which do not contain all event types.

This patch changes getsockopt behaviour to no longer return an error if not enough bytes are being provided by the user. Instead, it returns as much of sctp_event_subscribe as fits into the provided buffer.

Quoted 8 lines
Quoted 6 lines

This leads to the new behavior that users see what they have been aware of at compile time.

The setsockopt(..., SCTP_EVENTS, ...) API is already behaving like this.

Applied, but I had to fix the Subject to read "sctp: " not "scpt: " :-)