From: Jiri Pirko <jpirko@redhat.com> Date: Mon, 26 Apr 2010 15:47:54 -0400 Subject: [net] sctp: file must be valid before setting timeout Message-id: <20100426154754.GL2941@psychotron.lab.eng.brq.redhat.com> Patchwork-id: 24624 O-Subject: [RHEL5.6 patch] BZ578261 net: SCTP: Check to make sure file is valid before setting timeout Bugzilla: 578261 RH-Acked-by: Neil Horman <nhorman@redhat.com> RH-Acked-by: John Feeney <jfeeney@redhat.com> RH-Acked-by: Dean Nelson <dnelson@redhat.com> BZ578261 https://bugzilla.redhat.com/show_bug.cgi?id=578261 Description: In-kernel sockets created with sock_create_kern don't usually have a file and file descriptor allocated to them. As a result, when SCTP tries to check the non-blocking flag, we Oops when dereferencing a NULL file pointer. Upstream: http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff_plain;h=f50f95cab735ebe2993e8d1549f0615bad05f3f2 Brew: https://brewweb.devel.redhat.com/taskinfo?taskID=2401567 Tested on x86_64. Works as expected. Jirka Signed-off-by: Jiri Pirko <jpirko@redhat.com> Signed-off-by: Jarod Wilson <jarod@redhat.com> diff --git a/net/sctp/socket.c b/net/sctp/socket.c index a60f7d8..32d4750 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -1002,6 +1002,7 @@ static int __sctp_connect(struct sock* sk, int walk_size = 0; struct sockaddr *sa_addr; void *addr_buf; + unsigned int f_flags = 0; sp = sctp_sk(sk); ep = sp->ep; @@ -1123,7 +1124,14 @@ static int __sctp_connect(struct sock* sk, af->to_sk_daddr(&to, sk); sk->sk_err = 0; - timeo = sock_sndtimeo(sk, sk->sk_socket->file->f_flags & O_NONBLOCK); + /* in-kernel sockets don't generally have a file allocated to them + * if all they do is call sock_create_kern(). + */ + if (sk->sk_socket->file) + f_flags = sk->sk_socket->file->f_flags; + + timeo = sock_sndtimeo(sk, f_flags & O_NONBLOCK); + err = sctp_wait_for_connect(asoc, &timeo); /* Don't free association on exit. */