@@ -81,8 +81,6 @@ static int sctp_process_param(struct sctp_association *asoc,
81
81
gfp_t gfp );
82
82
static void * sctp_addto_param (struct sctp_chunk * chunk , int len ,
83
83
const void * data );
84
- static void * sctp_addto_chunk_fixed (struct sctp_chunk * , int len ,
85
- const void * data );
86
84
87
85
/* Control chunk destructor */
88
86
static void sctp_control_release_owner (struct sk_buff * skb )
@@ -154,9 +152,8 @@ static const struct sctp_paramhdr prsctp_param = {
154
152
cpu_to_be16 (sizeof (struct sctp_paramhdr )),
155
153
};
156
154
157
- /* A helper to initialize an op error inside a
158
- * provided chunk, as most cause codes will be embedded inside an
159
- * abort chunk.
155
+ /* A helper to initialize an op error inside a provided chunk, as most
156
+ * cause codes will be embedded inside an abort chunk.
160
157
*/
161
158
int sctp_init_cause (struct sctp_chunk * chunk , __be16 cause_code ,
162
159
size_t paylen )
@@ -177,29 +174,6 @@ int sctp_init_cause(struct sctp_chunk *chunk, __be16 cause_code,
177
174
return 0 ;
178
175
}
179
176
180
- /* A helper to initialize an op error inside a
181
- * provided chunk, as most cause codes will be embedded inside an
182
- * abort chunk. Differs from sctp_init_cause in that it won't oops
183
- * if there isn't enough space in the op error chunk
184
- */
185
- static int sctp_init_cause_fixed (struct sctp_chunk * chunk , __be16 cause_code ,
186
- size_t paylen )
187
- {
188
- struct sctp_errhdr err ;
189
- __u16 len ;
190
-
191
- /* Cause code constants are now defined in network order. */
192
- err .cause = cause_code ;
193
- len = sizeof (err ) + paylen ;
194
- err .length = htons (len );
195
-
196
- if (skb_tailroom (chunk -> skb ) < len )
197
- return - ENOSPC ;
198
-
199
- chunk -> subh .err_hdr = sctp_addto_chunk_fixed (chunk , sizeof (err ), & err );
200
-
201
- return 0 ;
202
- }
203
177
/* 3.3.2 Initiation (INIT) (1)
204
178
*
205
179
* This chunk is used to initiate a SCTP association between two
@@ -1263,20 +1237,26 @@ static struct sctp_chunk *sctp_make_op_error_space(
1263
1237
return retval ;
1264
1238
}
1265
1239
1266
- /* Create an Operation Error chunk of a fixed size,
1267
- * specifically, max(asoc->pathmtu, SCTP_DEFAULT_MAXSEGMENT)
1268
- * This is a helper function to allocate an error chunk for
1269
- * for those invalid parameter codes in which we may not want
1270
- * to report all the errors, if the incoming chunk is large
1240
+ /* Create an Operation Error chunk of a fixed size, specifically,
1241
+ * min(asoc->pathmtu, SCTP_DEFAULT_MAXSEGMENT) - overheads.
1242
+ * This is a helper function to allocate an error chunk for for those
1243
+ * invalid parameter codes in which we may not want to report all the
1244
+ * errors, if the incoming chunk is large. If it can't fit in a single
1245
+ * packet, we ignore it.
1271
1246
*/
1272
- static inline struct sctp_chunk * sctp_make_op_error_fixed (
1247
+ static inline struct sctp_chunk * sctp_make_op_error_limited (
1273
1248
const struct sctp_association * asoc ,
1274
1249
const struct sctp_chunk * chunk )
1275
1250
{
1276
- size_t size = asoc ? asoc -> pathmtu : 0 ;
1251
+ size_t size = SCTP_DEFAULT_MAXSEGMENT ;
1252
+ struct sctp_sock * sp = NULL ;
1253
+
1254
+ if (asoc ) {
1255
+ size = min_t (size_t , size , asoc -> pathmtu );
1256
+ sp = sctp_sk (asoc -> base .sk );
1257
+ }
1277
1258
1278
- if (!size )
1279
- size = SCTP_DEFAULT_MAXSEGMENT ;
1259
+ size = sctp_mtu_payload (sp , size , sizeof (struct sctp_errhdr ));
1280
1260
1281
1261
return sctp_make_op_error_space (asoc , chunk , size );
1282
1262
}
@@ -1528,18 +1508,6 @@ void *sctp_addto_chunk(struct sctp_chunk *chunk, int len, const void *data)
1528
1508
return target ;
1529
1509
}
1530
1510
1531
- /* Append bytes to the end of a chunk. Returns NULL if there isn't sufficient
1532
- * space in the chunk
1533
- */
1534
- static void * sctp_addto_chunk_fixed (struct sctp_chunk * chunk ,
1535
- int len , const void * data )
1536
- {
1537
- if (skb_tailroom (chunk -> skb ) >= len )
1538
- return sctp_addto_chunk (chunk , len , data );
1539
- else
1540
- return NULL ;
1541
- }
1542
-
1543
1511
/* Append bytes from user space to the end of a chunk. Will panic if
1544
1512
* chunk is not big enough.
1545
1513
* Returns a kernel err value.
@@ -1834,6 +1802,9 @@ struct sctp_association *sctp_unpack_cookie(
1834
1802
kt = ktime_get_real ();
1835
1803
1836
1804
if (!asoc && ktime_before (bear_cookie -> expiration , kt )) {
1805
+ suseconds_t usecs = ktime_to_us (ktime_sub (kt , bear_cookie -> expiration ));
1806
+ __be32 n = htonl (usecs );
1807
+
1837
1808
/*
1838
1809
* Section 3.3.10.3 Stale Cookie Error (3)
1839
1810
*
@@ -1842,17 +1813,12 @@ struct sctp_association *sctp_unpack_cookie(
1842
1813
* Stale Cookie Error: Indicates the receipt of a valid State
1843
1814
* Cookie that has expired.
1844
1815
*/
1845
- len = ntohs (chunk -> chunk_hdr -> length );
1846
- * errp = sctp_make_op_error_space (asoc , chunk , len );
1847
- if (* errp ) {
1848
- suseconds_t usecs = ktime_to_us (ktime_sub (kt , bear_cookie -> expiration ));
1849
- __be32 n = htonl (usecs );
1850
-
1851
- sctp_init_cause (* errp , SCTP_ERROR_STALE_COOKIE ,
1852
- sizeof (n ));
1853
- sctp_addto_chunk (* errp , sizeof (n ), & n );
1816
+ * errp = sctp_make_op_error (asoc , chunk ,
1817
+ SCTP_ERROR_STALE_COOKIE , & n ,
1818
+ sizeof (n ), 0 );
1819
+ if (* errp )
1854
1820
* error = - SCTP_IERROR_STALE_COOKIE ;
1855
- } else
1821
+ else
1856
1822
* error = - SCTP_IERROR_NOMEM ;
1857
1823
1858
1824
goto fail ;
@@ -2003,12 +1969,8 @@ static int sctp_process_hn_param(const struct sctp_association *asoc,
2003
1969
if (* errp )
2004
1970
sctp_chunk_free (* errp );
2005
1971
2006
- * errp = sctp_make_op_error_space (asoc , chunk , len );
2007
-
2008
- if (* errp ) {
2009
- sctp_init_cause (* errp , SCTP_ERROR_DNS_FAILED , len );
2010
- sctp_addto_chunk (* errp , len , param .v );
2011
- }
1972
+ * errp = sctp_make_op_error (asoc , chunk , SCTP_ERROR_DNS_FAILED ,
1973
+ param .v , len , 0 );
2012
1974
2013
1975
/* Stop processing this chunk. */
2014
1976
return 0 ;
@@ -2133,23 +2095,23 @@ static enum sctp_ierror sctp_process_unk_param(
2133
2095
/* Make an ERROR chunk, preparing enough room for
2134
2096
* returning multiple unknown parameters.
2135
2097
*/
2136
- if (NULL == * errp )
2137
- * errp = sctp_make_op_error_fixed (asoc , chunk );
2138
-
2139
- if (* errp ) {
2140
- if (!sctp_init_cause_fixed (* errp , SCTP_ERROR_UNKNOWN_PARAM ,
2141
- SCTP_PAD4 (ntohs (param .p -> length ))))
2142
- sctp_addto_chunk_fixed (* errp ,
2143
- SCTP_PAD4 (ntohs (param .p -> length )),
2144
- param .v );
2145
- } else {
2146
- /* If there is no memory for generating the ERROR
2147
- * report as specified, an ABORT will be triggered
2148
- * to the peer and the association won't be
2149
- * established.
2150
- */
2151
- retval = SCTP_IERROR_NOMEM ;
2098
+ if (!* errp ) {
2099
+ * errp = sctp_make_op_error_limited (asoc , chunk );
2100
+ if (!* errp ) {
2101
+ /* If there is no memory for generating the
2102
+ * ERROR report as specified, an ABORT will be
2103
+ * triggered to the peer and the association
2104
+ * won't be established.
2105
+ */
2106
+ retval = SCTP_IERROR_NOMEM ;
2107
+ break ;
2108
+ }
2152
2109
}
2110
+
2111
+ if (!sctp_init_cause (* errp , SCTP_ERROR_UNKNOWN_PARAM ,
2112
+ ntohs (param .p -> length )))
2113
+ sctp_addto_chunk (* errp , ntohs (param .p -> length ),
2114
+ param .v );
2153
2115
break ;
2154
2116
default :
2155
2117
break ;
@@ -2225,10 +2187,10 @@ static enum sctp_ierror sctp_verify_param(struct net *net,
2225
2187
* MUST be aborted. The ABORT chunk SHOULD contain the error
2226
2188
* cause 'Protocol Violation'.
2227
2189
*/
2228
- if (SCTP_AUTH_RANDOM_LENGTH !=
2229
- ntohs ( param . p -> length ) - sizeof (struct sctp_paramhdr )) {
2190
+ if (SCTP_AUTH_RANDOM_LENGTH != ntohs ( param . p -> length ) -
2191
+ sizeof (struct sctp_paramhdr )) {
2230
2192
sctp_process_inv_paramlength (asoc , param .p ,
2231
- chunk , err_chunk );
2193
+ chunk , err_chunk );
2232
2194
retval = SCTP_IERROR_ABORT ;
2233
2195
}
2234
2196
break ;
0 commit comments