2008-01-11 22:57:09 +08:00
|
|
|
/* SCTP kernel implementation
|
2005-04-17 06:20:36 +08:00
|
|
|
* (C) Copyright IBM Corp. 2003, 2004
|
|
|
|
*
|
2008-01-11 22:57:09 +08:00
|
|
|
* This file is part of the SCTP kernel implementation
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2007-05-09 14:57:56 +08:00
|
|
|
* This file contains the code relating the chunk abstraction.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2008-01-11 22:57:09 +08:00
|
|
|
* This SCTP implementation is free software;
|
2005-04-17 06:20:36 +08:00
|
|
|
* you can redistribute it and/or modify it under the terms of
|
|
|
|
* the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
2008-01-11 22:57:09 +08:00
|
|
|
* This SCTP implementation is distributed in the hope that it
|
2005-04-17 06:20:36 +08:00
|
|
|
* will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
|
|
|
* ************************
|
|
|
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2013-12-06 22:28:48 +08:00
|
|
|
* along with GNU CC; see the file COPYING. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Please send any bug reports or fixes you make to the
|
|
|
|
* email address(es):
|
2013-07-23 20:51:47 +08:00
|
|
|
* lksctp developers <linux-sctp@vger.kernel.org>
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Written or modified by:
|
|
|
|
* Jon Grimm <jgrimm@us.ibm.com>
|
|
|
|
* Sridhar Samudrala <sri@us.ibm.com>
|
|
|
|
*/
|
|
|
|
|
2010-08-24 21:21:08 +08:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/net.h>
|
|
|
|
#include <linux/inet.h>
|
|
|
|
#include <linux/skbuff.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <net/sock.h>
|
|
|
|
#include <net/sctp/sctp.h>
|
|
|
|
#include <net/sctp/sm.h>
|
|
|
|
|
|
|
|
/* This file is mostly in anticipation of future work, but initially
|
|
|
|
* populate with fragment tracking for an outbound message.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Initialize datamsg from memory. */
|
|
|
|
static void sctp_datamsg_init(struct sctp_datamsg *msg)
|
|
|
|
{
|
|
|
|
atomic_set(&msg->refcnt, 1);
|
|
|
|
msg->send_failed = 0;
|
|
|
|
msg->send_error = 0;
|
|
|
|
msg->can_abandon = 0;
|
2010-05-01 10:41:10 +08:00
|
|
|
msg->can_delay = 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
msg->expires_at = 0;
|
|
|
|
INIT_LIST_HEAD(&msg->chunks);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate and initialize datamsg. */
|
2013-06-17 17:40:05 +08:00
|
|
|
static struct sctp_datamsg *sctp_datamsg_new(gfp_t gfp)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct sctp_datamsg *msg;
|
|
|
|
msg = kmalloc(sizeof(struct sctp_datamsg), gfp);
|
2008-04-10 16:57:24 +08:00
|
|
|
if (msg) {
|
2005-04-17 06:20:36 +08:00
|
|
|
sctp_datamsg_init(msg);
|
2008-04-10 16:57:24 +08:00
|
|
|
SCTP_DBG_OBJCNT_INC(datamsg);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Final destructruction of datamsg memory. */
|
|
|
|
static void sctp_datamsg_destroy(struct sctp_datamsg *msg)
|
|
|
|
{
|
|
|
|
struct list_head *pos, *temp;
|
|
|
|
struct sctp_chunk *chunk;
|
|
|
|
struct sctp_sock *sp;
|
|
|
|
struct sctp_ulpevent *ev;
|
|
|
|
struct sctp_association *asoc = NULL;
|
|
|
|
int error = 0, notify;
|
|
|
|
|
|
|
|
/* If we failed, we may need to notify. */
|
|
|
|
notify = msg->send_failed ? -1 : 0;
|
|
|
|
|
|
|
|
/* Release all references. */
|
|
|
|
list_for_each_safe(pos, temp, &msg->chunks) {
|
|
|
|
list_del_init(pos);
|
|
|
|
chunk = list_entry(pos, struct sctp_chunk, frag_list);
|
|
|
|
/* Check whether we _really_ need to notify. */
|
|
|
|
if (notify < 0) {
|
|
|
|
asoc = chunk->asoc;
|
|
|
|
if (msg->send_error)
|
|
|
|
error = msg->send_error;
|
|
|
|
else
|
|
|
|
error = asoc->outqueue.error;
|
|
|
|
|
|
|
|
sp = sctp_sk(asoc->base.sk);
|
|
|
|
notify = sctp_ulpevent_type_enabled(SCTP_SEND_FAILED,
|
|
|
|
&sp->subscribe);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Generate a SEND FAILED event only if enabled. */
|
|
|
|
if (notify > 0) {
|
|
|
|
int sent;
|
|
|
|
if (chunk->has_tsn)
|
|
|
|
sent = SCTP_DATA_SENT;
|
|
|
|
else
|
|
|
|
sent = SCTP_DATA_UNSENT;
|
|
|
|
|
|
|
|
ev = sctp_ulpevent_make_send_failed(asoc, chunk, sent,
|
|
|
|
error, GFP_ATOMIC);
|
|
|
|
if (ev)
|
|
|
|
sctp_ulpq_tail_event(&asoc->ulpq, ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
sctp_chunk_put(chunk);
|
|
|
|
}
|
|
|
|
|
|
|
|
SCTP_DBG_OBJCNT_DEC(datamsg);
|
|
|
|
kfree(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Hold a reference. */
|
|
|
|
static void sctp_datamsg_hold(struct sctp_datamsg *msg)
|
|
|
|
{
|
|
|
|
atomic_inc(&msg->refcnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release a reference. */
|
|
|
|
void sctp_datamsg_put(struct sctp_datamsg *msg)
|
|
|
|
{
|
|
|
|
if (atomic_dec_and_test(&msg->refcnt))
|
|
|
|
sctp_datamsg_destroy(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Assign a chunk to this datamsg. */
|
|
|
|
static void sctp_datamsg_assign(struct sctp_datamsg *msg, struct sctp_chunk *chunk)
|
|
|
|
{
|
|
|
|
sctp_datamsg_hold(msg);
|
|
|
|
chunk->msg = msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* A data chunk can have a maximum payload of (2^16 - 20). Break
|
|
|
|
* down any such message into smaller chunks. Opportunistically, fragment
|
|
|
|
* the chunks down to the current MTU constraints. We may get refragmented
|
|
|
|
* later if the PMTU changes, but it is _much better_ to fragment immediately
|
|
|
|
* with a reasonable guess than always doing our fragmentation on the
|
|
|
|
* soft-interrupt.
|
|
|
|
*/
|
|
|
|
struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
|
|
|
|
struct sctp_sndrcvinfo *sinfo,
|
2014-11-15 14:11:23 +08:00
|
|
|
struct iov_iter *from)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int max, whole, i, offset, over, err;
|
|
|
|
int len, first_len;
|
2009-09-05 06:20:56 +08:00
|
|
|
int max_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct sctp_chunk *chunk;
|
|
|
|
struct sctp_datamsg *msg;
|
|
|
|
struct list_head *pos, *temp;
|
2014-11-15 14:11:23 +08:00
|
|
|
size_t msg_len = iov_iter_count(from);
|
2005-04-17 06:20:36 +08:00
|
|
|
__u8 frag;
|
|
|
|
|
|
|
|
msg = sctp_datamsg_new(GFP_KERNEL);
|
|
|
|
if (!msg)
|
sctp: fix -ENOMEM result with invalid user space pointer in sendto() syscall
Consider the following program, that sets the second argument to the
sendto() syscall incorrectly:
#include <string.h>
#include <arpa/inet.h>
#include <sys/socket.h>
int main(void)
{
int fd;
struct sockaddr_in sa;
fd = socket(AF_INET, SOCK_STREAM, 132 /*IPPROTO_SCTP*/);
if (fd < 0)
return 1;
memset(&sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_addr.s_addr = inet_addr("127.0.0.1");
sa.sin_port = htons(11111);
sendto(fd, NULL, 1, 0, (struct sockaddr *)&sa, sizeof(sa));
return 0;
}
We get -ENOMEM:
$ strace -e sendto ./demo
sendto(3, NULL, 1, 0, {sa_family=AF_INET, sin_port=htons(11111), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 ENOMEM (Cannot allocate memory)
Propagate the error code from sctp_user_addto_chunk(), so that we will
tell user space what actually went wrong:
$ strace -e sendto ./demo
sendto(3, NULL, 1, 0, {sa_family=AF_INET, sin_port=htons(11111), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EFAULT (Bad address)
Noticed while running Trinity (the syscall fuzzer).
Signed-off-by: Tommi Rantala <tt.rantala@gmail.com>
Acked-by: Vlad Yasevich <vyasevich@gmail.com>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2012-11-22 11:23:16 +08:00
|
|
|
return ERR_PTR(-ENOMEM);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Note: Calculate this outside of the loop, so that all fragments
|
|
|
|
* have the same expiration.
|
|
|
|
*/
|
|
|
|
if (sinfo->sinfo_timetolive) {
|
|
|
|
/* sinfo_timetolive is in milliseconds */
|
|
|
|
msg->expires_at = jiffies +
|
|
|
|
msecs_to_jiffies(sinfo->sinfo_timetolive);
|
|
|
|
msg->can_abandon = 1;
|
net: sctp: rework debugging framework to use pr_debug and friends
We should get rid of all own SCTP debug printk macros and use the ones
that the kernel offers anyway instead. This makes the code more readable
and conform to the kernel code, and offers all the features of dynamic
debbuging that pr_debug() et al has, such as only turning on/off portions
of debug messages at runtime through debugfs. The runtime cost of having
CONFIG_DYNAMIC_DEBUG enabled, but none of the debug statements printing,
is negligible [1]. If kernel debugging is completly turned off, then these
statements will also compile into "empty" functions.
While we're at it, we also need to change the Kconfig option as it /now/
only refers to the ifdef'ed code portions in outqueue.c that enable further
debugging/tracing of SCTP transaction fields. Also, since SCTP_ASSERT code
was enabled with this Kconfig option and has now been removed, we
transform those code parts into WARNs resp. where appropriate BUG_ONs so
that those bugs can be more easily detected as probably not many people
have SCTP debugging permanently turned on.
To turn on all SCTP debugging, the following steps are needed:
# mount -t debugfs none /sys/kernel/debug
# echo -n 'module sctp +p' > /sys/kernel/debug/dynamic_debug/control
This can be done more fine-grained on a per file, per line basis and others
as described in [2].
[1] https://www.kernel.org/doc/ols/2009/ols2009-pages-39-46.pdf
[2] Documentation/dynamic-debug-howto.txt
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-06-29 01:49:40 +08:00
|
|
|
|
|
|
|
pr_debug("%s: msg:%p expires_at:%ld jiffies:%ld\n", __func__,
|
|
|
|
msg, msg->expires_at, jiffies);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-09-05 06:20:56 +08:00
|
|
|
/* This is the biggest possible DATA chunk that can fit into
|
|
|
|
* the packet
|
|
|
|
*/
|
net: sctp: Fix data chunk fragmentation for MTU values which are not multiple of 4
net: sctp: Fix data chunk fragmentation for MTU values which are not multiple of 4
Initially the problem was observed with ipsec, but later it became clear that
SCTP data chunk fragmentation algorithm has problems with MTU values which are
not multiple of 4. Test program was used which just transmits 2000 bytes long
packets to other host. tcpdump was used to observe re-fragmentation in IP layer
after SCTP already fragmented data chunks.
With MTU 1500:
12:54:34.082904 IP (tos 0x2,ECT(0), ttl 64, id 0, offset 0, flags [DF], proto SCTP (132), length 1500)
10.151.38.153.39303 > 10.151.24.91.54321: sctp (1) [DATA] (B) [TSN: 2366088589] [SID: 0] [SSEQ 1] [PPID 0x0]
12:54:34.082933 IP (tos 0x2,ECT(0), ttl 64, id 0, offset 0, flags [DF], proto SCTP (132), length 596)
10.151.38.153.39303 > 10.151.24.91.54321: sctp (1) [DATA] (E) [TSN: 2366088590] [SID: 0] [SSEQ 1] [PPID 0x0]
12:54:34.090576 IP (tos 0x2,ECT(0), ttl 63, id 0, offset 0, flags [DF], proto SCTP (132), length 48)
10.151.24.91.54321 > 10.151.38.153.39303: sctp (1) [SACK] [cum ack 2366088590] [a_rwnd 79920] [#gap acks 0] [#dup tsns 0]
With MTU 1499:
13:02:49.955220 IP (tos 0x2,ECT(0), ttl 64, id 48215, offset 0, flags [+], proto SCTP (132), length 1492)
10.151.38.153.39084 > 10.151.24.91.54321: sctp[|sctp]
13:02:49.955249 IP (tos 0x2,ECT(0), ttl 64, id 48215, offset 1472, flags [none], proto SCTP (132), length 28)
10.151.38.153 > 10.151.24.91: ip-proto-132
13:02:49.955262 IP (tos 0x2,ECT(0), ttl 64, id 0, offset 0, flags [DF], proto SCTP (132), length 600)
10.151.38.153.39084 > 10.151.24.91.54321: sctp (1) [DATA] (E) [TSN: 404355346] [SID: 0] [SSEQ 1] [PPID 0x0]
13:02:49.956770 IP (tos 0x2,ECT(0), ttl 63, id 0, offset 0, flags [DF], proto SCTP (132), length 48)
10.151.24.91.54321 > 10.151.38.153.39084: sctp (1) [SACK] [cum ack 404355346] [a_rwnd 79920] [#gap acks 0] [#dup tsns 0]
Here problem in data portion limit calculation leads to re-fragmentation in IP,
which is sub-optimal. The problem is max_data initial value, which doesn't take
into account the fact, that data chunk must be padded to 4-bytes boundary.
It's enough to correct max_data, because all later adjustments are correctly
aligned to 4-bytes boundary.
After the fix is applied, everything is fragmented correctly for uneven MTUs:
15:16:27.083881 IP (tos 0x2,ECT(0), ttl 64, id 0, offset 0, flags [DF], proto SCTP (132), length 1496)
10.151.38.153.53417 > 10.151.24.91.54321: sctp (1) [DATA] (B) [TSN: 3077098183] [SID: 0] [SSEQ 1] [PPID 0x0]
15:16:27.083907 IP (tos 0x2,ECT(0), ttl 64, id 0, offset 0, flags [DF], proto SCTP (132), length 600)
10.151.38.153.53417 > 10.151.24.91.54321: sctp (1) [DATA] (E) [TSN: 3077098184] [SID: 0] [SSEQ 1] [PPID 0x0]
15:16:27.085640 IP (tos 0x2,ECT(0), ttl 63, id 0, offset 0, flags [DF], proto SCTP (132), length 48)
10.151.24.91.54321 > 10.151.38.153.53417: sctp (1) [SACK] [cum ack 3077098184] [a_rwnd 79920] [#gap acks 0] [#dup tsns 0]
The bug was there for years already, but
- is a performance issue, the packets are still transmitted
- doesn't show up with default MTU 1500, but possibly with ipsec (MTU 1438)
Signed-off-by: Alexander Sverdlin <alexander.sverdlin@nsn.com>
Acked-by: Vlad Yasevich <vyasevich@gmail.com>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-09-02 21:58:25 +08:00
|
|
|
max_data = (asoc->pathmtu -
|
2009-09-05 06:20:56 +08:00
|
|
|
sctp_sk(asoc->base.sk)->pf->af->net_header_len -
|
net: sctp: Fix data chunk fragmentation for MTU values which are not multiple of 4
net: sctp: Fix data chunk fragmentation for MTU values which are not multiple of 4
Initially the problem was observed with ipsec, but later it became clear that
SCTP data chunk fragmentation algorithm has problems with MTU values which are
not multiple of 4. Test program was used which just transmits 2000 bytes long
packets to other host. tcpdump was used to observe re-fragmentation in IP layer
after SCTP already fragmented data chunks.
With MTU 1500:
12:54:34.082904 IP (tos 0x2,ECT(0), ttl 64, id 0, offset 0, flags [DF], proto SCTP (132), length 1500)
10.151.38.153.39303 > 10.151.24.91.54321: sctp (1) [DATA] (B) [TSN: 2366088589] [SID: 0] [SSEQ 1] [PPID 0x0]
12:54:34.082933 IP (tos 0x2,ECT(0), ttl 64, id 0, offset 0, flags [DF], proto SCTP (132), length 596)
10.151.38.153.39303 > 10.151.24.91.54321: sctp (1) [DATA] (E) [TSN: 2366088590] [SID: 0] [SSEQ 1] [PPID 0x0]
12:54:34.090576 IP (tos 0x2,ECT(0), ttl 63, id 0, offset 0, flags [DF], proto SCTP (132), length 48)
10.151.24.91.54321 > 10.151.38.153.39303: sctp (1) [SACK] [cum ack 2366088590] [a_rwnd 79920] [#gap acks 0] [#dup tsns 0]
With MTU 1499:
13:02:49.955220 IP (tos 0x2,ECT(0), ttl 64, id 48215, offset 0, flags [+], proto SCTP (132), length 1492)
10.151.38.153.39084 > 10.151.24.91.54321: sctp[|sctp]
13:02:49.955249 IP (tos 0x2,ECT(0), ttl 64, id 48215, offset 1472, flags [none], proto SCTP (132), length 28)
10.151.38.153 > 10.151.24.91: ip-proto-132
13:02:49.955262 IP (tos 0x2,ECT(0), ttl 64, id 0, offset 0, flags [DF], proto SCTP (132), length 600)
10.151.38.153.39084 > 10.151.24.91.54321: sctp (1) [DATA] (E) [TSN: 404355346] [SID: 0] [SSEQ 1] [PPID 0x0]
13:02:49.956770 IP (tos 0x2,ECT(0), ttl 63, id 0, offset 0, flags [DF], proto SCTP (132), length 48)
10.151.24.91.54321 > 10.151.38.153.39084: sctp (1) [SACK] [cum ack 404355346] [a_rwnd 79920] [#gap acks 0] [#dup tsns 0]
Here problem in data portion limit calculation leads to re-fragmentation in IP,
which is sub-optimal. The problem is max_data initial value, which doesn't take
into account the fact, that data chunk must be padded to 4-bytes boundary.
It's enough to correct max_data, because all later adjustments are correctly
aligned to 4-bytes boundary.
After the fix is applied, everything is fragmented correctly for uneven MTUs:
15:16:27.083881 IP (tos 0x2,ECT(0), ttl 64, id 0, offset 0, flags [DF], proto SCTP (132), length 1496)
10.151.38.153.53417 > 10.151.24.91.54321: sctp (1) [DATA] (B) [TSN: 3077098183] [SID: 0] [SSEQ 1] [PPID 0x0]
15:16:27.083907 IP (tos 0x2,ECT(0), ttl 64, id 0, offset 0, flags [DF], proto SCTP (132), length 600)
10.151.38.153.53417 > 10.151.24.91.54321: sctp (1) [DATA] (E) [TSN: 3077098184] [SID: 0] [SSEQ 1] [PPID 0x0]
15:16:27.085640 IP (tos 0x2,ECT(0), ttl 63, id 0, offset 0, flags [DF], proto SCTP (132), length 48)
10.151.24.91.54321 > 10.151.38.153.53417: sctp (1) [SACK] [cum ack 3077098184] [a_rwnd 79920] [#gap acks 0] [#dup tsns 0]
The bug was there for years already, but
- is a performance issue, the packets are still transmitted
- doesn't show up with default MTU 1500, but possibly with ipsec (MTU 1438)
Signed-off-by: Alexander Sverdlin <alexander.sverdlin@nsn.com>
Acked-by: Vlad Yasevich <vyasevich@gmail.com>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-09-02 21:58:25 +08:00
|
|
|
sizeof(struct sctphdr) - sizeof(struct sctp_data_chunk)) & ~3;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-09-05 06:20:56 +08:00
|
|
|
max = asoc->frag_point;
|
2007-09-17 10:32:45 +08:00
|
|
|
/* If the the peer requested that we authenticate DATA chunks
|
2013-10-26 16:06:30 +08:00
|
|
|
* we need to account for bundling of the AUTH chunks along with
|
2007-09-17 10:32:45 +08:00
|
|
|
* DATA.
|
|
|
|
*/
|
|
|
|
if (sctp_auth_send_cid(SCTP_CID_DATA, asoc)) {
|
|
|
|
struct sctp_hmac *hmac_desc = sctp_auth_asoc_get_hmac(asoc);
|
|
|
|
|
|
|
|
if (hmac_desc)
|
2009-09-05 06:20:56 +08:00
|
|
|
max_data -= WORD_ROUND(sizeof(sctp_auth_chunk_t) +
|
2007-09-17 10:32:45 +08:00
|
|
|
hmac_desc->hmac_len);
|
|
|
|
}
|
|
|
|
|
2009-09-05 06:20:56 +08:00
|
|
|
/* Now, check if we need to reduce our max */
|
|
|
|
if (max > max_data)
|
|
|
|
max = max_data;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
whole = 0;
|
|
|
|
first_len = max;
|
|
|
|
|
2009-08-08 01:23:28 +08:00
|
|
|
/* Check to see if we have a pending SACK and try to let it be bundled
|
|
|
|
* with this message. Do this if we don't have any data queued already.
|
|
|
|
* To check that, look at out_qlen and retransmit list.
|
|
|
|
* NOTE: we will not reduce to account for SACK, if the message would
|
|
|
|
* not have been fragmented.
|
|
|
|
*/
|
|
|
|
if (timer_pending(&asoc->timers[SCTP_EVENT_TIMEOUT_SACK]) &&
|
|
|
|
asoc->outqueue.out_qlen == 0 &&
|
|
|
|
list_empty(&asoc->outqueue.retransmit) &&
|
|
|
|
msg_len > max)
|
|
|
|
max_data -= WORD_ROUND(sizeof(sctp_sack_chunk_t));
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Encourage Cookie-ECHO bundling. */
|
2009-08-08 01:23:28 +08:00
|
|
|
if (asoc->state < SCTP_STATE_COOKIE_ECHOED)
|
2009-09-05 06:20:56 +08:00
|
|
|
max_data -= SCTP_ARBITRARY_COOKIE_ECHO_LEN;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-08-08 01:23:28 +08:00
|
|
|
/* Now that we adjusted completely, reset first_len */
|
|
|
|
if (first_len > max_data)
|
|
|
|
first_len = max_data;
|
2009-09-05 06:20:56 +08:00
|
|
|
|
|
|
|
/* Account for a different sized first fragment */
|
|
|
|
if (msg_len >= first_len) {
|
|
|
|
msg_len -= first_len;
|
|
|
|
whole = 1;
|
2010-05-01 10:41:10 +08:00
|
|
|
msg->can_delay = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* How many full sized? How many bytes leftover? */
|
|
|
|
whole += msg_len / max;
|
|
|
|
over = msg_len % max;
|
|
|
|
offset = 0;
|
|
|
|
|
|
|
|
if ((whole > 1) || (whole && over))
|
2012-08-06 16:47:55 +08:00
|
|
|
SCTP_INC_STATS_USER(sock_net(asoc->base.sk), SCTP_MIB_FRAGUSRMSGS);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Create chunks for all the full sized DATA chunks. */
|
2013-12-23 12:16:50 +08:00
|
|
|
for (i = 0, len = first_len; i < whole; i++) {
|
2005-04-17 06:20:36 +08:00
|
|
|
frag = SCTP_DATA_MIDDLE_FRAG;
|
|
|
|
|
|
|
|
if (0 == i)
|
|
|
|
frag |= SCTP_DATA_FIRST_FRAG;
|
|
|
|
|
2009-11-24 04:53:56 +08:00
|
|
|
if ((i == (whole - 1)) && !over) {
|
2005-04-17 06:20:36 +08:00
|
|
|
frag |= SCTP_DATA_LAST_FRAG;
|
|
|
|
|
2009-11-24 04:53:56 +08:00
|
|
|
/* The application requests to set the I-bit of the
|
|
|
|
* last DATA chunk of a user message when providing
|
|
|
|
* the user message to the SCTP implementation.
|
|
|
|
*/
|
|
|
|
if ((sinfo->sinfo_flags & SCTP_EOF) ||
|
|
|
|
(sinfo->sinfo_flags & SCTP_SACK_IMMEDIATELY))
|
|
|
|
frag |= SCTP_DATA_SACK_IMM;
|
|
|
|
}
|
|
|
|
|
2016-03-11 05:33:07 +08:00
|
|
|
chunk = sctp_make_datafrag_empty(asoc, sinfo, len, frag,
|
|
|
|
0, GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
sctp: fix -ENOMEM result with invalid user space pointer in sendto() syscall
Consider the following program, that sets the second argument to the
sendto() syscall incorrectly:
#include <string.h>
#include <arpa/inet.h>
#include <sys/socket.h>
int main(void)
{
int fd;
struct sockaddr_in sa;
fd = socket(AF_INET, SOCK_STREAM, 132 /*IPPROTO_SCTP*/);
if (fd < 0)
return 1;
memset(&sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_addr.s_addr = inet_addr("127.0.0.1");
sa.sin_port = htons(11111);
sendto(fd, NULL, 1, 0, (struct sockaddr *)&sa, sizeof(sa));
return 0;
}
We get -ENOMEM:
$ strace -e sendto ./demo
sendto(3, NULL, 1, 0, {sa_family=AF_INET, sin_port=htons(11111), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 ENOMEM (Cannot allocate memory)
Propagate the error code from sctp_user_addto_chunk(), so that we will
tell user space what actually went wrong:
$ strace -e sendto ./demo
sendto(3, NULL, 1, 0, {sa_family=AF_INET, sin_port=htons(11111), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EFAULT (Bad address)
Noticed while running Trinity (the syscall fuzzer).
Signed-off-by: Tommi Rantala <tt.rantala@gmail.com>
Acked-by: Vlad Yasevich <vyasevich@gmail.com>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2012-11-22 11:23:16 +08:00
|
|
|
if (!chunk) {
|
|
|
|
err = -ENOMEM;
|
2005-04-17 06:20:36 +08:00
|
|
|
goto errout;
|
sctp: fix -ENOMEM result with invalid user space pointer in sendto() syscall
Consider the following program, that sets the second argument to the
sendto() syscall incorrectly:
#include <string.h>
#include <arpa/inet.h>
#include <sys/socket.h>
int main(void)
{
int fd;
struct sockaddr_in sa;
fd = socket(AF_INET, SOCK_STREAM, 132 /*IPPROTO_SCTP*/);
if (fd < 0)
return 1;
memset(&sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_addr.s_addr = inet_addr("127.0.0.1");
sa.sin_port = htons(11111);
sendto(fd, NULL, 1, 0, (struct sockaddr *)&sa, sizeof(sa));
return 0;
}
We get -ENOMEM:
$ strace -e sendto ./demo
sendto(3, NULL, 1, 0, {sa_family=AF_INET, sin_port=htons(11111), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 ENOMEM (Cannot allocate memory)
Propagate the error code from sctp_user_addto_chunk(), so that we will
tell user space what actually went wrong:
$ strace -e sendto ./demo
sendto(3, NULL, 1, 0, {sa_family=AF_INET, sin_port=htons(11111), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EFAULT (Bad address)
Noticed while running Trinity (the syscall fuzzer).
Signed-off-by: Tommi Rantala <tt.rantala@gmail.com>
Acked-by: Vlad Yasevich <vyasevich@gmail.com>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2012-11-22 11:23:16 +08:00
|
|
|
}
|
|
|
|
|
2014-11-15 14:11:23 +08:00
|
|
|
err = sctp_user_addto_chunk(chunk, len, from);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (err < 0)
|
sctp: fix memory leak in sctp_datamsg_from_user() when copy from user space fails
Trinity (the syscall fuzzer) discovered a memory leak in SCTP,
reproducible e.g. with the sendto() syscall by passing invalid
user space pointer in the second argument:
#include <string.h>
#include <arpa/inet.h>
#include <sys/socket.h>
int main(void)
{
int fd;
struct sockaddr_in sa;
fd = socket(AF_INET, SOCK_STREAM, 132 /*IPPROTO_SCTP*/);
if (fd < 0)
return 1;
memset(&sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_addr.s_addr = inet_addr("127.0.0.1");
sa.sin_port = htons(11111);
sendto(fd, NULL, 1, 0, (struct sockaddr *)&sa, sizeof(sa));
return 0;
}
As far as I can tell, the leak has been around since ~2003.
Signed-off-by: Tommi Rantala <tt.rantala@gmail.com>
Acked-by: Vlad Yasevich <vyasevich@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2012-11-27 12:01:46 +08:00
|
|
|
goto errout_chunk_free;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Put the chunk->skb back into the form expected by send. */
|
|
|
|
__skb_pull(chunk->skb, (__u8 *)chunk->chunk_hdr
|
|
|
|
- (__u8 *)chunk->skb->data);
|
|
|
|
|
|
|
|
sctp_datamsg_assign(msg, chunk);
|
|
|
|
list_add_tail(&chunk->frag_list, &msg->chunks);
|
|
|
|
|
|
|
|
/* The first chunk, the first chunk was likely short
|
|
|
|
* to allow bundling, so reset to full size.
|
|
|
|
*/
|
|
|
|
if (0 == i)
|
|
|
|
len = max;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* .. now the leftover bytes. */
|
|
|
|
if (over) {
|
|
|
|
if (!whole)
|
|
|
|
frag = SCTP_DATA_NOT_FRAG;
|
|
|
|
else
|
|
|
|
frag = SCTP_DATA_LAST_FRAG;
|
|
|
|
|
2009-11-24 04:53:56 +08:00
|
|
|
if ((sinfo->sinfo_flags & SCTP_EOF) ||
|
|
|
|
(sinfo->sinfo_flags & SCTP_SACK_IMMEDIATELY))
|
|
|
|
frag |= SCTP_DATA_SACK_IMM;
|
|
|
|
|
2016-03-11 05:33:07 +08:00
|
|
|
chunk = sctp_make_datafrag_empty(asoc, sinfo, over, frag,
|
|
|
|
0, GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
sctp: fix -ENOMEM result with invalid user space pointer in sendto() syscall
Consider the following program, that sets the second argument to the
sendto() syscall incorrectly:
#include <string.h>
#include <arpa/inet.h>
#include <sys/socket.h>
int main(void)
{
int fd;
struct sockaddr_in sa;
fd = socket(AF_INET, SOCK_STREAM, 132 /*IPPROTO_SCTP*/);
if (fd < 0)
return 1;
memset(&sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_addr.s_addr = inet_addr("127.0.0.1");
sa.sin_port = htons(11111);
sendto(fd, NULL, 1, 0, (struct sockaddr *)&sa, sizeof(sa));
return 0;
}
We get -ENOMEM:
$ strace -e sendto ./demo
sendto(3, NULL, 1, 0, {sa_family=AF_INET, sin_port=htons(11111), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 ENOMEM (Cannot allocate memory)
Propagate the error code from sctp_user_addto_chunk(), so that we will
tell user space what actually went wrong:
$ strace -e sendto ./demo
sendto(3, NULL, 1, 0, {sa_family=AF_INET, sin_port=htons(11111), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EFAULT (Bad address)
Noticed while running Trinity (the syscall fuzzer).
Signed-off-by: Tommi Rantala <tt.rantala@gmail.com>
Acked-by: Vlad Yasevich <vyasevich@gmail.com>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2012-11-22 11:23:16 +08:00
|
|
|
if (!chunk) {
|
|
|
|
err = -ENOMEM;
|
2005-04-17 06:20:36 +08:00
|
|
|
goto errout;
|
sctp: fix -ENOMEM result with invalid user space pointer in sendto() syscall
Consider the following program, that sets the second argument to the
sendto() syscall incorrectly:
#include <string.h>
#include <arpa/inet.h>
#include <sys/socket.h>
int main(void)
{
int fd;
struct sockaddr_in sa;
fd = socket(AF_INET, SOCK_STREAM, 132 /*IPPROTO_SCTP*/);
if (fd < 0)
return 1;
memset(&sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_addr.s_addr = inet_addr("127.0.0.1");
sa.sin_port = htons(11111);
sendto(fd, NULL, 1, 0, (struct sockaddr *)&sa, sizeof(sa));
return 0;
}
We get -ENOMEM:
$ strace -e sendto ./demo
sendto(3, NULL, 1, 0, {sa_family=AF_INET, sin_port=htons(11111), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 ENOMEM (Cannot allocate memory)
Propagate the error code from sctp_user_addto_chunk(), so that we will
tell user space what actually went wrong:
$ strace -e sendto ./demo
sendto(3, NULL, 1, 0, {sa_family=AF_INET, sin_port=htons(11111), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EFAULT (Bad address)
Noticed while running Trinity (the syscall fuzzer).
Signed-off-by: Tommi Rantala <tt.rantala@gmail.com>
Acked-by: Vlad Yasevich <vyasevich@gmail.com>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2012-11-22 11:23:16 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-11-15 14:11:23 +08:00
|
|
|
err = sctp_user_addto_chunk(chunk, over, from);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Put the chunk->skb back into the form expected by send. */
|
|
|
|
__skb_pull(chunk->skb, (__u8 *)chunk->chunk_hdr
|
|
|
|
- (__u8 *)chunk->skb->data);
|
|
|
|
if (err < 0)
|
sctp: fix memory leak in sctp_datamsg_from_user() when copy from user space fails
Trinity (the syscall fuzzer) discovered a memory leak in SCTP,
reproducible e.g. with the sendto() syscall by passing invalid
user space pointer in the second argument:
#include <string.h>
#include <arpa/inet.h>
#include <sys/socket.h>
int main(void)
{
int fd;
struct sockaddr_in sa;
fd = socket(AF_INET, SOCK_STREAM, 132 /*IPPROTO_SCTP*/);
if (fd < 0)
return 1;
memset(&sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_addr.s_addr = inet_addr("127.0.0.1");
sa.sin_port = htons(11111);
sendto(fd, NULL, 1, 0, (struct sockaddr *)&sa, sizeof(sa));
return 0;
}
As far as I can tell, the leak has been around since ~2003.
Signed-off-by: Tommi Rantala <tt.rantala@gmail.com>
Acked-by: Vlad Yasevich <vyasevich@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2012-11-27 12:01:46 +08:00
|
|
|
goto errout_chunk_free;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
sctp_datamsg_assign(msg, chunk);
|
|
|
|
list_add_tail(&chunk->frag_list, &msg->chunks);
|
|
|
|
}
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
|
sctp: fix memory leak in sctp_datamsg_from_user() when copy from user space fails
Trinity (the syscall fuzzer) discovered a memory leak in SCTP,
reproducible e.g. with the sendto() syscall by passing invalid
user space pointer in the second argument:
#include <string.h>
#include <arpa/inet.h>
#include <sys/socket.h>
int main(void)
{
int fd;
struct sockaddr_in sa;
fd = socket(AF_INET, SOCK_STREAM, 132 /*IPPROTO_SCTP*/);
if (fd < 0)
return 1;
memset(&sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_addr.s_addr = inet_addr("127.0.0.1");
sa.sin_port = htons(11111);
sendto(fd, NULL, 1, 0, (struct sockaddr *)&sa, sizeof(sa));
return 0;
}
As far as I can tell, the leak has been around since ~2003.
Signed-off-by: Tommi Rantala <tt.rantala@gmail.com>
Acked-by: Vlad Yasevich <vyasevich@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2012-11-27 12:01:46 +08:00
|
|
|
errout_chunk_free:
|
|
|
|
sctp_chunk_free(chunk);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
errout:
|
|
|
|
list_for_each_safe(pos, temp, &msg->chunks) {
|
|
|
|
list_del_init(pos);
|
|
|
|
chunk = list_entry(pos, struct sctp_chunk, frag_list);
|
|
|
|
sctp_chunk_free(chunk);
|
|
|
|
}
|
2008-03-24 13:47:08 +08:00
|
|
|
sctp_datamsg_put(msg);
|
sctp: fix -ENOMEM result with invalid user space pointer in sendto() syscall
Consider the following program, that sets the second argument to the
sendto() syscall incorrectly:
#include <string.h>
#include <arpa/inet.h>
#include <sys/socket.h>
int main(void)
{
int fd;
struct sockaddr_in sa;
fd = socket(AF_INET, SOCK_STREAM, 132 /*IPPROTO_SCTP*/);
if (fd < 0)
return 1;
memset(&sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_addr.s_addr = inet_addr("127.0.0.1");
sa.sin_port = htons(11111);
sendto(fd, NULL, 1, 0, (struct sockaddr *)&sa, sizeof(sa));
return 0;
}
We get -ENOMEM:
$ strace -e sendto ./demo
sendto(3, NULL, 1, 0, {sa_family=AF_INET, sin_port=htons(11111), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 ENOMEM (Cannot allocate memory)
Propagate the error code from sctp_user_addto_chunk(), so that we will
tell user space what actually went wrong:
$ strace -e sendto ./demo
sendto(3, NULL, 1, 0, {sa_family=AF_INET, sin_port=htons(11111), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EFAULT (Bad address)
Noticed while running Trinity (the syscall fuzzer).
Signed-off-by: Tommi Rantala <tt.rantala@gmail.com>
Acked-by: Vlad Yasevich <vyasevich@gmail.com>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2012-11-22 11:23:16 +08:00
|
|
|
return ERR_PTR(err);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check whether this message has expired. */
|
|
|
|
int sctp_chunk_abandoned(struct sctp_chunk *chunk)
|
|
|
|
{
|
|
|
|
struct sctp_datamsg *msg = chunk->msg;
|
|
|
|
|
|
|
|
if (!msg->can_abandon)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (time_after(jiffies, msg->expires_at))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This chunk (and consequently entire message) has failed in its sending. */
|
|
|
|
void sctp_chunk_fail(struct sctp_chunk *chunk, int error)
|
|
|
|
{
|
|
|
|
chunk->msg->send_failed = 1;
|
|
|
|
chunk->msg->send_error = error;
|
|
|
|
}
|