~ubuntu-branches/ubuntu/wily/linux-ti-omap4/wily

« back to all changes in this revision

Viewing changes to net/ipv4/tcp_input.c

  • Committer: Package Import Robot
  • Author(s): Paolo Pisati, Paolo Pisati, Ubuntu: 3.5.0-25.38
  • Date: 2013-02-20 22:03:31 UTC
  • mfrom: (74.1.1 quantal-proposed)
  • Revision ID: package-import@ubuntu.com-20130220220331-0ea4l33x3cr61nch
Tags: 3.5.0-220.28
* Release Tracking Bug
  - LP: #1130311

[ Paolo Pisati ]

* rebased on Ubuntu-3.5.0-25.38

[ Ubuntu: 3.5.0-25.38 ]

* Release Tracking Bug
  - LP: #1129472
* ptrace: introduce signal_wake_up_state() and ptrace_signal_wake_up()
  - LP: #1119885, #1129192
  - CVE-2013-0871
* ptrace: ensure arch_ptrace/ptrace_request can never race with SIGKILL
  - LP: #1119885, #1129192
  - CVE-2013-0871
* wake_up_process() should be never used to wakeup a TASK_STOPPED/TRACED
  task
  - LP: #1119885, #1129192
  - CVE-2013-0871

Show diffs side-by-side

added added

removed removed

Lines of Context:
88
88
int sysctl_tcp_adv_win_scale __read_mostly = 1;
89
89
EXPORT_SYMBOL(sysctl_tcp_adv_win_scale);
90
90
 
 
91
/* rfc5961 challenge ack rate limiting */
 
92
int sysctl_tcp_challenge_ack_limit = 100;
 
93
 
91
94
int sysctl_tcp_stdurg __read_mostly;
92
95
int sysctl_tcp_rfc1337 __read_mostly;
93
96
int sysctl_tcp_max_orphans __read_mostly = NR_FILE;
3760
3763
        return false;
3761
3764
}
3762
3765
 
 
3766
/* RFC 5961 7 [ACK Throttling] */
 
3767
static void tcp_send_challenge_ack(struct sock *sk)
 
3768
{
 
3769
        /* unprotected vars, we dont care of overwrites */
 
3770
        static u32 challenge_timestamp;
 
3771
        static unsigned int challenge_count;
 
3772
        u32 now = jiffies / HZ;
 
3773
 
 
3774
        if (now != challenge_timestamp) {
 
3775
                challenge_timestamp = now;
 
3776
                challenge_count = 0;
 
3777
        }
 
3778
        if (++challenge_count <= sysctl_tcp_challenge_ack_limit) {
 
3779
                NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_TCPCHALLENGEACK);
 
3780
                tcp_send_ack(sk);
 
3781
        }
 
3782
}
 
3783
 
3763
3784
/* This routine deals with incoming acks, but not outgoing ones. */
3764
3785
static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)
3765
3786
{
3779
3800
        /* If the ack is older than previous acks
3780
3801
         * then we can probably ignore it.
3781
3802
         */
3782
 
        if (before(ack, prior_snd_una))
 
3803
        if (before(ack, prior_snd_una)) {
 
3804
                /* RFC 5961 5.2 [Blind Data Injection Attack].[Mitigation] */
 
3805
                if (before(ack, prior_snd_una - tp->max_window)) {
 
3806
                        tcp_send_challenge_ack(sk);
 
3807
                        return -1;
 
3808
                }
3783
3809
                goto old_ack;
 
3810
        }
3784
3811
 
3785
3812
        /* If the ack includes data we haven't sent yet, discard
3786
3813
         * this segment (RFC793 Section 3.9).
5431
5458
/* Does PAWS and seqno based validation of an incoming segment, flags will
5432
5459
 * play significant role here.
5433
5460
 */
5434
 
static int tcp_validate_incoming(struct sock *sk, struct sk_buff *skb,
5435
 
                              const struct tcphdr *th, int syn_inerr)
 
5461
static bool tcp_validate_incoming(struct sock *sk, struct sk_buff *skb,
 
5462
                                  const struct tcphdr *th, int syn_inerr)
5436
5463
{
5437
5464
        const u8 *hash_location;
5438
5465
        struct tcp_sock *tp = tcp_sk(sk);
5457
5484
                 * an acknowledgment should be sent in reply (unless the RST
5458
5485
                 * bit is set, if so drop the segment and return)".
5459
5486
                 */
5460
 
                if (!th->rst)
 
5487
                if (!th->rst) {
 
5488
                        if (th->syn)
 
5489
                                goto syn_challenge;
5461
5490
                        tcp_send_dupack(sk, skb);
 
5491
                }
5462
5492
                goto discard;
5463
5493
        }
5464
5494
 
5465
5495
        /* Step 2: check RST bit */
5466
5496
        if (th->rst) {
5467
 
                tcp_reset(sk);
 
5497
                /* RFC 5961 3.2 :
 
5498
                 * If sequence number exactly matches RCV.NXT, then
 
5499
                 *     RESET the connection
 
5500
                 * else
 
5501
                 *     Send a challenge ACK
 
5502
                 */
 
5503
                if (TCP_SKB_CB(skb)->seq == tp->rcv_nxt)
 
5504
                        tcp_reset(sk);
 
5505
                else
 
5506
                        tcp_send_challenge_ack(sk);
5468
5507
                goto discard;
5469
5508
        }
5470
5509
 
5471
 
        /* ts_recent update must be made after we are sure that the packet
5472
 
         * is in window.
5473
 
         */
5474
 
        tcp_replace_ts_recent(tp, TCP_SKB_CB(skb)->seq);
5475
 
 
5476
5510
        /* step 3: check security and precedence [ignored] */
5477
5511
 
5478
 
        /* step 4: Check for a SYN in window. */
5479
 
        if (th->syn && !before(TCP_SKB_CB(skb)->seq, tp->rcv_nxt)) {
 
5512
        /* step 4: Check for a SYN
 
5513
         * RFC 5691 4.2 : Send a challenge ack
 
5514
         */
 
5515
        if (th->syn) {
 
5516
syn_challenge:
5480
5517
                if (syn_inerr)
5481
5518
                        TCP_INC_STATS_BH(sock_net(sk), TCP_MIB_INERRS);
5482
 
                NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_TCPABORTONSYN);
5483
 
                tcp_reset(sk);
5484
 
                return -1;
 
5519
                NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_TCPSYNCHALLENGE);
 
5520
                tcp_send_challenge_ack(sk);
 
5521
                goto discard;
5485
5522
        }
5486
5523
 
5487
 
        return 1;
 
5524
        return true;
5488
5525
 
5489
5526
discard:
5490
5527
        __kfree_skb(skb);
5491
 
        return 0;
 
5528
        return false;
5492
5529
}
5493
5530
 
5494
5531
/*
5518
5555
                        const struct tcphdr *th, unsigned int len)
5519
5556
{
5520
5557
        struct tcp_sock *tp = tcp_sk(sk);
5521
 
        int res;
5522
5558
 
5523
5559
        /*
5524
5560
         *      Header prediction.
5696
5732
         *      Standard slow path.
5697
5733
         */
5698
5734
 
5699
 
        res = tcp_validate_incoming(sk, skb, th, 1);
5700
 
        if (res <= 0)
5701
 
                return -res;
 
5735
        if (!tcp_validate_incoming(sk, skb, th, 1))
 
5736
                return 0;
5702
5737
 
5703
5738
step5:
5704
5739
        if (th->ack && tcp_ack(sk, skb, FLAG_SLOWPATH) < 0)
5705
5740
                goto discard;
5706
5741
 
 
5742
        /* ts_recent update must be made after we are sure that the packet
 
5743
         * is in window.
 
5744
         */
 
5745
        tcp_replace_ts_recent(tp, TCP_SKB_CB(skb)->seq);
 
5746
 
5707
5747
        tcp_rcv_rtt_measure_ts(sk, skb);
5708
5748
 
5709
5749
        /* Process urgent data. */
6016
6056
        struct tcp_sock *tp = tcp_sk(sk);
6017
6057
        struct inet_connection_sock *icsk = inet_csk(sk);
6018
6058
        int queued = 0;
6019
 
        int res;
6020
6059
 
6021
6060
        tp->rx_opt.saw_tstamp = 0;
6022
6061
 
6071
6110
                return 0;
6072
6111
        }
6073
6112
 
6074
 
        res = tcp_validate_incoming(sk, skb, th, 0);
6075
 
        if (res <= 0)
6076
 
                return -res;
 
6113
        if (!tcp_validate_incoming(sk, skb, th, 0))
 
6114
                return 0;
6077
6115
 
6078
6116
        /* step 5: check the ACK field */
6079
6117
        if (th->ack) {
6184
6222
        } else
6185
6223
                goto discard;
6186
6224
 
 
6225
        /* ts_recent update must be made after we are sure that the packet
 
6226
         * is in window.
 
6227
         */
 
6228
        tcp_replace_ts_recent(tp, TCP_SKB_CB(skb)->seq);
 
6229
 
6187
6230
        /* step 6: check the URG bit */
6188
6231
        tcp_urg(sk, skb, th);
6189
6232