* [PATCH net-next 0/5]: SCTP updates
2008-12-20 1:47 [PATCH net-next 0/5]: SCTP updates Vlad Yasevich
@ 2008-12-20 1:47 ` Vlad Yasevich
2008-12-20 1:47 ` [PATCH net-next 1/5] sctp: Bring SCTP_MAXSEG socket option into ietf API extension compliance Vlad Yasevich
` (4 subsequent siblings)
5 siblings, 0 replies; 14+ messages in thread
From: Vlad Yasevich @ 2008-12-20 1:47 UTC (permalink / raw)
To: netdev; +Cc: davem, linux-sctp
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH net-next 1/5] sctp: Bring SCTP_MAXSEG socket option into ietf API extension compliance
2008-12-20 1:47 [PATCH net-next 0/5]: SCTP updates Vlad Yasevich
2008-12-20 1:47 ` Vlad Yasevich
@ 2008-12-20 1:47 ` Vlad Yasevich
2008-12-26 0:56 ` David Miller
2008-12-20 1:47 ` [PATCH net-next 2/5] sctp: Fix a typo in socket.c Vlad Yasevich
` (3 subsequent siblings)
5 siblings, 1 reply; 14+ messages in thread
From: Vlad Yasevich @ 2008-12-20 1:47 UTC (permalink / raw)
To: netdev; +Cc: davem, linux-sctp, Wei Yongjun, Vlad Yasevich
From: Wei Yongjun <yjwei@cn.fujitsu.com>
Brings maxseg socket option set/get into line with the latest ietf socket
extensions API draft, while maintaining backwards compatibility.
Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com>
---
net/sctp/socket.c | 130 +++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 107 insertions(+), 23 deletions(-)
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index a2de585..0738843 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -2778,32 +2778,77 @@ static int sctp_setsockopt_mappedv4(struct sock *sk, char __user *optval, int op
}
/*
- * 7.1.17 Set the maximum fragrmentation size (SCTP_MAXSEG)
- *
- * This socket option specifies the maximum size to put in any outgoing
- * SCTP chunk. If a message is larger than this size it will be
+ * 8.1.16. Get or Set the Maximum Fragmentation Size (SCTP_MAXSEG)
+ * This option will get or set the maximum size to put in any outgoing
+ * SCTP DATA chunk. If a message is larger than this size it will be
* fragmented by SCTP into the specified size. Note that the underlying
* SCTP implementation may fragment into smaller sized chunks when the
* PMTU of the underlying association is smaller than the value set by
- * the user.
+ * the user. The default value for this option is '0' which indicates
+ * the user is NOT limiting fragmentation and only the PMTU will effect
+ * SCTP's choice of DATA chunk size. Note also that values set larger
+ * than the maximum size of an IP datagram will effectively let SCTP
+ * control fragmentation (i.e. the same as setting this option to 0).
+ *
+ * The following structure is used to access and modify this parameter:
+ *
+ * struct sctp_assoc_value {
+ * sctp_assoc_t assoc_id;
+ * uint32_t assoc_value;
+ * };
+ *
+ * assoc_id: This parameter is ignored for one-to-one style sockets.
+ * For one-to-many style sockets this parameter indicates which
+ * association the user is performing an action upon. Note that if
+ * this field's value is zero then the endpoints default value is
+ * changed (effecting future associations only).
+ * assoc_value: This parameter specifies the maximum size in bytes.
*/
static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, int optlen)
{
+ struct sctp_assoc_value params;
struct sctp_association *asoc;
struct sctp_sock *sp = sctp_sk(sk);
int val;
- if (optlen < sizeof(int))
+ if (optlen == sizeof(int)) {
+ printk(KERN_WARNING
+ "SCTP: Use of int in maxseg socket option deprecated\n");
+ printk(KERN_WARNING
+ "SCTP: Use struct sctp_assoc_value instead\n");
+ if (copy_from_user(&val, optval, optlen))
+ return -EFAULT;
+ params.assoc_id = 0;
+ } else if (optlen == sizeof(struct sctp_assoc_value)) {
+ if (copy_from_user(¶ms, optval, optlen))
+ return -EFAULT;
+ val = params.assoc_value;
+ } else
return -EINVAL;
- if (get_user(val, (int __user *)optval))
- return -EFAULT;
+
if ((val != 0) && ((val < 8) || (val > SCTP_MAX_CHUNK_LEN)))
return -EINVAL;
- sp->user_frag = val;
- /* Update the frag_point of the existing associations. */
- list_for_each_entry(asoc, &(sp->ep->asocs), asocs) {
- asoc->frag_point = sctp_frag_point(sp, asoc->pathmtu);
+ asoc = sctp_id2assoc(sk, params.assoc_id);
+ if (!asoc && params.assoc_id && sctp_style(sk, UDP))
+ return -EINVAL;
+
+ if (asoc) {
+ if (val == 0) {
+ val = asoc->pathmtu;
+ val -= sp->pf->af->net_header_len;
+ val -= sizeof(struct sctphdr) +
+ sizeof(struct sctp_data_chunk);
+ }
+
+ asoc->frag_point = val;
+ } else {
+ sp->user_frag = val;
+
+ /* Update the frag_point of the existing associations. */
+ list_for_each_entry(asoc, &(sp->ep->asocs), asocs) {
+ asoc->frag_point = sctp_frag_point(sp, asoc->pathmtu);
+ }
}
return 0;
@@ -5100,30 +5145,69 @@ static int sctp_getsockopt_context(struct sock *sk, int len,
}
/*
- * 7.1.17 Set the maximum fragrmentation size (SCTP_MAXSEG)
- *
- * This socket option specifies the maximum size to put in any outgoing
- * SCTP chunk. If a message is larger than this size it will be
+ * 8.1.16. Get or Set the Maximum Fragmentation Size (SCTP_MAXSEG)
+ * This option will get or set the maximum size to put in any outgoing
+ * SCTP DATA chunk. If a message is larger than this size it will be
* fragmented by SCTP into the specified size. Note that the underlying
* SCTP implementation may fragment into smaller sized chunks when the
* PMTU of the underlying association is smaller than the value set by
- * the user.
+ * the user. The default value for this option is '0' which indicates
+ * the user is NOT limiting fragmentation and only the PMTU will effect
+ * SCTP's choice of DATA chunk size. Note also that values set larger
+ * than the maximum size of an IP datagram will effectively let SCTP
+ * control fragmentation (i.e. the same as setting this option to 0).
+ *
+ * The following structure is used to access and modify this parameter:
+ *
+ * struct sctp_assoc_value {
+ * sctp_assoc_t assoc_id;
+ * uint32_t assoc_value;
+ * };
+ *
+ * assoc_id: This parameter is ignored for one-to-one style sockets.
+ * For one-to-many style sockets this parameter indicates which
+ * association the user is performing an action upon. Note that if
+ * this field's value is zero then the endpoints default value is
+ * changed (effecting future associations only).
+ * assoc_value: This parameter specifies the maximum size in bytes.
*/
static int sctp_getsockopt_maxseg(struct sock *sk, int len,
char __user *optval, int __user *optlen)
{
- int val;
+ struct sctp_assoc_value params;
+ struct sctp_association *asoc;
- if (len < sizeof(int))
+ if (len == sizeof(int)) {
+ printk(KERN_WARNING
+ "SCTP: Use of int in maxseg socket option deprecated\n");
+ printk(KERN_WARNING
+ "SCTP: Use struct sctp_assoc_value instead\n");
+ params.assoc_id = 0;
+ } else if (len >= sizeof(struct sctp_assoc_value)) {
+ len = sizeof(struct sctp_assoc_value);
+ if (copy_from_user(¶ms, optval, sizeof(params)))
+ return -EFAULT;
+ } else
return -EINVAL;
- len = sizeof(int);
+ asoc = sctp_id2assoc(sk, params.assoc_id);
+ if (!asoc && params.assoc_id && sctp_style(sk, UDP))
+ return -EINVAL;
+
+ if (asoc)
+ params.assoc_value = asoc->frag_point;
+ else
+ params.assoc_value = sctp_sk(sk)->user_frag;
- val = sctp_sk(sk)->user_frag;
if (put_user(len, optlen))
return -EFAULT;
- if (copy_to_user(optval, &val, len))
- return -EFAULT;
+ if (len == sizeof(int)) {
+ if (copy_to_user(optval, ¶ms.assoc_value, len))
+ return -EFAULT;
+ } else {
+ if (copy_to_user(optval, ¶ms, len))
+ return -EFAULT;
+ }
return 0;
}
--
1.5.3.5
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH net-next 1/5] sctp: Bring SCTP_MAXSEG socket option into ietf API extension compliance
2008-12-20 1:47 ` [PATCH net-next 1/5] sctp: Bring SCTP_MAXSEG socket option into ietf API extension compliance Vlad Yasevich
@ 2008-12-26 0:56 ` David Miller
2008-12-26 17:04 ` Vlad Yasevich
0 siblings, 1 reply; 14+ messages in thread
From: David Miller @ 2008-12-26 0:56 UTC (permalink / raw)
To: vladislav.yasevich; +Cc: netdev, linux-sctp, yjwei
From: Vlad Yasevich <vladislav.yasevich@hp.com>
Date: Fri, 19 Dec 2008 20:47:48 -0500
> From: Wei Yongjun <yjwei@cn.fujitsu.com>
>
> Brings maxseg socket option set/get into line with the latest ietf socket
> extensions API draft, while maintaining backwards compatibility.
>
> Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
> Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com>
Applied. But I really dislike this scheme used by the compat code.
Half-way initializing a structure and then depending upon the logic in
the rest of the function to make sure the rest of the struct (the
uninitialized part) is never accessed?
Give me a break, programming, auditing, and bug fixing is hard enough
as it is without sloppy code like this.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH net-next 1/5] sctp: Bring SCTP_MAXSEG socket option into ietf API extension compliance
2008-12-26 0:56 ` David Miller
@ 2008-12-26 17:04 ` Vlad Yasevich
2008-12-26 19:15 ` David Miller
0 siblings, 1 reply; 14+ messages in thread
From: Vlad Yasevich @ 2008-12-26 17:04 UTC (permalink / raw)
To: David Miller; +Cc: netdev, linux-sctp, yjwei
David Miller wrote:
> From: Vlad Yasevich <vladislav.yasevich@hp.com>
> Date: Fri, 19 Dec 2008 20:47:48 -0500
>
>> From: Wei Yongjun <yjwei@cn.fujitsu.com>
>>
>> Brings maxseg socket option set/get into line with the latest ietf socket
>> extensions API draft, while maintaining backwards compatibility.
>>
>> Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
>> Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com>
>
> Applied. But I really dislike this scheme used by the compat code.
> Half-way initializing a structure and then depending upon the logic in
> the rest of the function to make sure the rest of the struct (the
> uninitialized part) is never accessed?
>
> Give me a break, programming, auditing, and bug fixing is hard enough
> as it is without sloppy code like this.
Yes, it sucks but the since the draft keeps breaking the ABI between revisions,
it leaves us a between a rock (no support) and a hard place (crappy code).
-vlad
> --
> To unsubscribe from this list: send the line "unsubscribe linux-sctp" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH net-next 1/5] sctp: Bring SCTP_MAXSEG socket option into ietf API extension compliance
2008-12-26 17:04 ` Vlad Yasevich
@ 2008-12-26 19:15 ` David Miller
0 siblings, 0 replies; 14+ messages in thread
From: David Miller @ 2008-12-26 19:15 UTC (permalink / raw)
To: vladislav.yasevich; +Cc: netdev, linux-sctp, yjwei
From: Vlad Yasevich <vladislav.yasevich@hp.com>
Date: Fri, 26 Dec 2008 12:04:14 -0500
> David Miller wrote:
> > From: Vlad Yasevich <vladislav.yasevich@hp.com>
> > Date: Fri, 19 Dec 2008 20:47:48 -0500
> >
> >> From: Wei Yongjun <yjwei@cn.fujitsu.com>
> >>
> >> Brings maxseg socket option set/get into line with the latest ietf socket
> >> extensions API draft, while maintaining backwards compatibility.
> >>
> >> Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
> >> Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com>
> >
> > Applied. But I really dislike this scheme used by the compat code.
> > Half-way initializing a structure and then depending upon the logic in
> > the rest of the function to make sure the rest of the struct (the
> > uninitialized part) is never accessed?
> >
> > Give me a break, programming, auditing, and bug fixing is hard enough
> > as it is without sloppy code like this.
>
> Yes, it sucks but the since the draft keeps breaking the ABI between revisions,
> it leaves us a between a rock (no support) and a hard place (crappy code).
In this specific case we could have simply memset() the on-stack
structure to zero and there would be no confusion about whether the
object is initialized in some way in all code paths.
Or, in the main initial conditional we could explicitly assign both
members of this structure in both branches.
This is not about the compatibility issues, it's about how this code
was written.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH net-next 2/5] sctp: Fix a typo in socket.c
2008-12-20 1:47 [PATCH net-next 0/5]: SCTP updates Vlad Yasevich
2008-12-20 1:47 ` Vlad Yasevich
2008-12-20 1:47 ` [PATCH net-next 1/5] sctp: Bring SCTP_MAXSEG socket option into ietf API extension compliance Vlad Yasevich
@ 2008-12-20 1:47 ` Vlad Yasevich
2008-12-26 0:57 ` David Miller
2008-12-20 1:47 ` [PATCH net-next 3/5] sctp: Implement socket option SCTP_GET_ASSOC_NUMBER Vlad Yasevich
` (2 subsequent siblings)
5 siblings, 1 reply; 14+ messages in thread
From: Vlad Yasevich @ 2008-12-20 1:47 UTC (permalink / raw)
To: netdev; +Cc: davem, linux-sctp, Wei Yongjun, Vlad Yasevich
From: Wei Yongjun <yjwei@cn.fujitsu.com>
Just fix a typo in socket.c.
Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com>
---
net/sctp/socket.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 0738843..e432927 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -2404,9 +2404,9 @@ static int sctp_setsockopt_delayed_ack(struct sock *sk,
if (params.sack_delay == 0 && params.sack_freq == 0)
return 0;
} else if (optlen == sizeof(struct sctp_assoc_value)) {
- printk(KERN_WARNING "SCTP: Use of struct sctp_sack_info "
+ printk(KERN_WARNING "SCTP: Use of struct sctp_assoc_value "
"in delayed_ack socket option deprecated\n");
- printk(KERN_WARNING "SCTP: struct sctp_sack_info instead\n");
+ printk(KERN_WARNING "SCTP: Use struct sctp_sack_info instead\n");
if (copy_from_user(¶ms, optval, optlen))
return -EFAULT;
@@ -4221,9 +4221,9 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
if (copy_from_user(¶ms, optval, len))
return -EFAULT;
} else if (len == sizeof(struct sctp_assoc_value)) {
- printk(KERN_WARNING "SCTP: Use of struct sctp_sack_info "
+ printk(KERN_WARNING "SCTP: Use of struct sctp_assoc_value "
"in delayed_ack socket option deprecated\n");
- printk(KERN_WARNING "SCTP: struct sctp_sack_info instead\n");
+ printk(KERN_WARNING "SCTP: Use struct sctp_sack_info instead\n");
if (copy_from_user(¶ms, optval, len))
return -EFAULT;
} else
--
1.5.3.5
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH net-next 3/5] sctp: Implement socket option SCTP_GET_ASSOC_NUMBER
2008-12-20 1:47 [PATCH net-next 0/5]: SCTP updates Vlad Yasevich
` (2 preceding siblings ...)
2008-12-20 1:47 ` [PATCH net-next 2/5] sctp: Fix a typo in socket.c Vlad Yasevich
@ 2008-12-20 1:47 ` Vlad Yasevich
2008-12-26 0:57 ` David Miller
2008-12-20 1:47 ` [PATCH net-next 4/5] sctp: Avoid memory overflow while FWD-TSN chunk is received with bad stream ID Vlad Yasevich
2008-12-20 1:47 ` [PATCH net-next 5/5] sctp: Add validity check for SCTP_PARTIAL_DELIVERY_POINT socket option Vlad Yasevich
5 siblings, 1 reply; 14+ messages in thread
From: Vlad Yasevich @ 2008-12-20 1:47 UTC (permalink / raw)
To: netdev; +Cc: davem, linux-sctp, Wei Yongjun, Vlad Yasevich
From: Wei Yongjun <yjwei@cn.fujitsu.com>
Implement socket option SCTP_GET_ASSOC_NUMBER of the latest ietf socket
extensions API draft.
8.2.5. Get the Current Number of Associations (SCTP_GET_ASSOC_NUMBER)
This option gets the current number of associations that are attached
to a one-to-many style socket. The option value is an uint32_t.
Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com>
---
include/net/sctp/user.h | 2 ++
net/sctp/socket.c | 35 +++++++++++++++++++++++++++++++++++
2 files changed, 37 insertions(+), 0 deletions(-)
diff --git a/include/net/sctp/user.h b/include/net/sctp/user.h
index f205b10..b259fc5 100644
--- a/include/net/sctp/user.h
+++ b/include/net/sctp/user.h
@@ -118,6 +118,8 @@ enum sctp_optname {
#define SCTP_PEER_AUTH_CHUNKS SCTP_PEER_AUTH_CHUNKS
SCTP_LOCAL_AUTH_CHUNKS, /* Read only */
#define SCTP_LOCAL_AUTH_CHUNKS SCTP_LOCAL_AUTH_CHUNKS
+ SCTP_GET_ASSOC_NUMBER, /* Read only */
+#define SCTP_GET_ASSOC_NUMBER SCTP_GET_ASSOC_NUMBER
/* Internal Socket Options. Some of the sctp library functions are
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index e432927..9f5fe23 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -5460,6 +5460,38 @@ num:
return 0;
}
+/*
+ * 8.2.5. Get the Current Number of Associations (SCTP_GET_ASSOC_NUMBER)
+ * This option gets the current number of associations that are attached
+ * to a one-to-many style socket. The option value is an uint32_t.
+ */
+static int sctp_getsockopt_assoc_number(struct sock *sk, int len,
+ char __user *optval, int __user *optlen)
+{
+ struct sctp_sock *sp = sctp_sk(sk);
+ struct sctp_association *asoc;
+ u32 val = 0;
+
+ if (sctp_style(sk, TCP))
+ return -EOPNOTSUPP;
+
+ if (len < sizeof(u32))
+ return -EINVAL;
+
+ len = sizeof(u32);
+
+ list_for_each_entry(asoc, &(sp->ep->asocs), asocs) {
+ val++;
+ }
+
+ if (put_user(len, optlen))
+ return -EFAULT;
+ if (copy_to_user(optval, &val, len))
+ return -EFAULT;
+
+ return 0;
+}
+
SCTP_STATIC int sctp_getsockopt(struct sock *sk, int level, int optname,
char __user *optval, int __user *optlen)
{
@@ -5602,6 +5634,9 @@ SCTP_STATIC int sctp_getsockopt(struct sock *sk, int level, int optname,
retval = sctp_getsockopt_local_auth_chunks(sk, len, optval,
optlen);
break;
+ case SCTP_GET_ASSOC_NUMBER:
+ retval = sctp_getsockopt_assoc_number(sk, len, optval, optlen);
+ break;
default:
retval = -ENOPROTOOPT;
break;
--
1.5.3.5
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH net-next 3/5] sctp: Implement socket option SCTP_GET_ASSOC_NUMBER
2008-12-20 1:47 ` [PATCH net-next 3/5] sctp: Implement socket option SCTP_GET_ASSOC_NUMBER Vlad Yasevich
@ 2008-12-26 0:57 ` David Miller
0 siblings, 0 replies; 14+ messages in thread
From: David Miller @ 2008-12-26 0:57 UTC (permalink / raw)
To: vladislav.yasevich; +Cc: netdev, linux-sctp, yjwei
From: Vlad Yasevich <vladislav.yasevich@hp.com>
Date: Fri, 19 Dec 2008 20:47:50 -0500
> From: Wei Yongjun <yjwei@cn.fujitsu.com>
>
> Implement socket option SCTP_GET_ASSOC_NUMBER of the latest ietf socket
> extensions API draft.
>
> 8.2.5. Get the Current Number of Associations (SCTP_GET_ASSOC_NUMBER)
>
> This option gets the current number of associations that are attached
> to a one-to-many style socket. The option value is an uint32_t.
>
> Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
> Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com>
Applied.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH net-next 4/5] sctp: Avoid memory overflow while FWD-TSN chunk is received with bad stream ID
2008-12-20 1:47 [PATCH net-next 0/5]: SCTP updates Vlad Yasevich
` (3 preceding siblings ...)
2008-12-20 1:47 ` [PATCH net-next 3/5] sctp: Implement socket option SCTP_GET_ASSOC_NUMBER Vlad Yasevich
@ 2008-12-20 1:47 ` Vlad Yasevich
2008-12-26 0:58 ` David Miller
2008-12-20 1:47 ` [PATCH net-next 5/5] sctp: Add validity check for SCTP_PARTIAL_DELIVERY_POINT socket option Vlad Yasevich
5 siblings, 1 reply; 14+ messages in thread
From: Vlad Yasevich @ 2008-12-20 1:47 UTC (permalink / raw)
To: netdev; +Cc: davem, linux-sctp, Wei Yongjun, Vlad Yasevich
From: Wei Yongjun <yjwei@cn.fujitsu.com>
If FWD-TSN chunk is received with bad stream ID, the sctp will not do the
validity check, this may cause memory overflow when overwrite the TSN of
the stream ID.
The FORWARD-TSN chunk is like this:
FORWARD-TSN chunk
Type = 192
Flags = 0
Length = 172
NewTSN = 99
Stream = 10000
StreamSequence = 0xFFFF
This patch fix this problem by discard the chunk if stream ID is not
less than MIS.
Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com>
---
net/sctp/sm_statefuns.c | 14 ++++++++++++++
1 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
index 9f2a3eb..1c4e5d6 100644
--- a/net/sctp/sm_statefuns.c
+++ b/net/sctp/sm_statefuns.c
@@ -3689,6 +3689,7 @@ sctp_disposition_t sctp_sf_eat_fwd_tsn(const struct sctp_endpoint *ep,
{
struct sctp_chunk *chunk = arg;
struct sctp_fwdtsn_hdr *fwdtsn_hdr;
+ struct sctp_fwdtsn_skip *skip;
__u16 len;
__u32 tsn;
@@ -3718,6 +3719,12 @@ sctp_disposition_t sctp_sf_eat_fwd_tsn(const struct sctp_endpoint *ep,
if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
goto discard_noforce;
+ /* Silently discard the chunk if stream-id is not valid */
+ sctp_walk_fwdtsn(skip, chunk) {
+ if (ntohs(skip->stream) >= asoc->c.sinit_max_instreams)
+ goto discard_noforce;
+ }
+
sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
if (len > sizeof(struct sctp_fwdtsn_hdr))
sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
@@ -3749,6 +3756,7 @@ sctp_disposition_t sctp_sf_eat_fwd_tsn_fast(
{
struct sctp_chunk *chunk = arg;
struct sctp_fwdtsn_hdr *fwdtsn_hdr;
+ struct sctp_fwdtsn_skip *skip;
__u16 len;
__u32 tsn;
@@ -3778,6 +3786,12 @@ sctp_disposition_t sctp_sf_eat_fwd_tsn_fast(
if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
goto gen_shutdown;
+ /* Silently discard the chunk if stream-id is not valid */
+ sctp_walk_fwdtsn(skip, chunk) {
+ if (ntohs(skip->stream) >= asoc->c.sinit_max_instreams)
+ goto gen_shutdown;
+ }
+
sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
if (len > sizeof(struct sctp_fwdtsn_hdr))
sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
--
1.5.3.5
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH net-next 4/5] sctp: Avoid memory overflow while FWD-TSN chunk is received with bad stream ID
2008-12-20 1:47 ` [PATCH net-next 4/5] sctp: Avoid memory overflow while FWD-TSN chunk is received with bad stream ID Vlad Yasevich
@ 2008-12-26 0:58 ` David Miller
0 siblings, 0 replies; 14+ messages in thread
From: David Miller @ 2008-12-26 0:58 UTC (permalink / raw)
To: vladislav.yasevich; +Cc: netdev, linux-sctp, yjwei
From: Vlad Yasevich <vladislav.yasevich@hp.com>
Date: Fri, 19 Dec 2008 20:47:51 -0500
> If FWD-TSN chunk is received with bad stream ID, the sctp will not do the
> validity check, this may cause memory overflow when overwrite the TSN of
> the stream ID.
>
> The FORWARD-TSN chunk is like this:
>
> FORWARD-TSN chunk
> Type = 192
> Flags = 0
> Length = 172
> NewTSN = 99
> Stream = 10000
> StreamSequence = 0xFFFF
>
> This patch fix this problem by discard the chunk if stream ID is not
> less than MIS.
>
> Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
> Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com>
Applied and queued up for -stable.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH net-next 5/5] sctp: Add validity check for SCTP_PARTIAL_DELIVERY_POINT socket option
2008-12-20 1:47 [PATCH net-next 0/5]: SCTP updates Vlad Yasevich
` (4 preceding siblings ...)
2008-12-20 1:47 ` [PATCH net-next 4/5] sctp: Avoid memory overflow while FWD-TSN chunk is received with bad stream ID Vlad Yasevich
@ 2008-12-20 1:47 ` Vlad Yasevich
2008-12-26 0:59 ` David Miller
5 siblings, 1 reply; 14+ messages in thread
From: Vlad Yasevich @ 2008-12-20 1:47 UTC (permalink / raw)
To: netdev; +Cc: davem, linux-sctp, Wei Yongjun, Vlad Yasevich
From: Wei Yongjun <yjwei@cn.fujitsu.com>
The latest ietf socket extensions API draft said:
8.1.21. Set or Get the SCTP Partial Delivery Point
Note also that the call will fail if the user attempts to set
this value larger than the socket receive buffer size.
This patch add this validity check for SCTP_PARTIAL_DELIVERY_POINT
socket option.
Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com>
---
net/sctp/socket.c | 19 ++++++++++++++++---
1 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 9f5fe23..b14a8f3 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -3010,14 +3010,21 @@ static int sctp_setsockopt_fragment_interleave(struct sock *sk,
}
/*
- * 7.1.25. Set or Get the sctp partial delivery point
+ * 8.1.21. Set or Get the SCTP Partial Delivery Point
* (SCTP_PARTIAL_DELIVERY_POINT)
+ *
* This option will set or get the SCTP partial delivery point. This
* point is the size of a message where the partial delivery API will be
* invoked to help free up rwnd space for the peer. Setting this to a
- * lower value will cause partial delivery's to happen more often. The
+ * lower value will cause partial deliveries to happen more often. The
* calls argument is an integer that sets or gets the partial delivery
- * point.
+ * point. Note also that the call will fail if the user attempts to set
+ * this value larger than the socket receive buffer size.
+ *
+ * Note that any single message having a length smaller than or equal to
+ * the SCTP partial delivery point will be delivered in one single read
+ * call as long as the user provided buffer is large enough to hold the
+ * message.
*/
static int sctp_setsockopt_partial_delivery_point(struct sock *sk,
char __user *optval,
@@ -3030,6 +3037,12 @@ static int sctp_setsockopt_partial_delivery_point(struct sock *sk,
if (get_user(val, (int __user *)optval))
return -EFAULT;
+ /* Note: We double the receive buffer from what the user sets
+ * it to be, also initial rwnd is based on rcvbuf/2.
+ */
+ if (val > (sk->sk_rcvbuf >> 1))
+ return -EINVAL;
+
sctp_sk(sk)->pd_point = val;
return 0; /* is this the right error code? */
--
1.5.3.5
^ permalink raw reply related [flat|nested] 14+ messages in thread