Skip to content

Commit ca35a0e

Browse files
Eric Dumazetdavem330
authored andcommitted
tcp: md5: dont write skb head in tcp_md5_hash_header()
tcp_md5_hash_header() writes into skb header a temporary zero value, this might confuse other users of this area. Since tcphdr is small (20 bytes), copy it in a temporary variable and make the change in the copy. Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 01718e3 commit ca35a0e

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

include/net/tcp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ extern void tcp_free_md5sig_pool(void);
12091209
extern struct tcp_md5sig_pool *tcp_get_md5sig_pool(void);
12101210
extern void tcp_put_md5sig_pool(void);
12111211

1212-
extern int tcp_md5_hash_header(struct tcp_md5sig_pool *, struct tcphdr *);
1212+
extern int tcp_md5_hash_header(struct tcp_md5sig_pool *, const struct tcphdr *);
12131213
extern int tcp_md5_hash_skb_data(struct tcp_md5sig_pool *, const struct sk_buff *,
12141214
unsigned header_len);
12151215
extern int tcp_md5_hash_key(struct tcp_md5sig_pool *hp,

net/ipv4/tcp.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2994,17 +2994,19 @@ void tcp_put_md5sig_pool(void)
29942994
EXPORT_SYMBOL(tcp_put_md5sig_pool);
29952995

29962996
int tcp_md5_hash_header(struct tcp_md5sig_pool *hp,
2997-
struct tcphdr *th)
2997+
const struct tcphdr *th)
29982998
{
29992999
struct scatterlist sg;
3000+
struct tcphdr hdr;
30003001
int err;
30013002

3002-
__sum16 old_checksum = th->check;
3003-
th->check = 0;
3003+
/* We are not allowed to change tcphdr, make a local copy */
3004+
memcpy(&hdr, th, sizeof(hdr));
3005+
hdr.check = 0;
3006+
30043007
/* options aren't included in the hash */
3005-
sg_init_one(&sg, th, sizeof(struct tcphdr));
3006-
err = crypto_hash_update(&hp->md5_desc, &sg, sizeof(struct tcphdr));
3007-
th->check = old_checksum;
3008+
sg_init_one(&sg, &hdr, sizeof(hdr));
3009+
err = crypto_hash_update(&hp->md5_desc, &sg, sizeof(hdr));
30083010
return err;
30093011
}
30103012
EXPORT_SYMBOL(tcp_md5_hash_header);

0 commit comments

Comments
 (0)