Skip to content
This repository has been archived by the owner on Mar 17, 2019. It is now read-only.

Commit

Permalink
ipsec: check return value of skb_to_sgvec always
Browse files Browse the repository at this point in the history
commit 3f29770723fe498a5c5f57c3a31a996ebdde03e1 upstream.

Signed-off-by: Jason A. Donenfeld <[email protected]>
Cc: Steffen Klassert <[email protected]>
Cc: Herbert Xu <[email protected]>
Cc: "David S. Miller" <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
[nc: Adjust context due to lack of 000ae7b2690e2 and fca11ebde3f0]
Signed-off-by: Nathan Chancellor <[email protected]>
  • Loading branch information
zx2c4 authored and Harsh Shandilya committed Apr 5, 2018
1 parent f7f67bd commit a946f4e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
8 changes: 6 additions & 2 deletions net/ipv4/ah4.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ static int ah_output(struct xfrm_state *x, struct sk_buff *skb)
ah->seq_no = htonl(XFRM_SKB_CB(skb)->seq.output.low);

sg_init_table(sg, nfrags + sglists);
skb_to_sgvec_nomark(skb, sg, 0, skb->len);
err = skb_to_sgvec_nomark(skb, sg, 0, skb->len);
if (unlikely(err < 0))
goto out_free;

if (x->props.flags & XFRM_STATE_ESN) {
/* Attach seqhi sg right after packet payload */
Expand Down Expand Up @@ -391,7 +393,9 @@ static int ah_input(struct xfrm_state *x, struct sk_buff *skb)
skb_push(skb, ihl);

sg_init_table(sg, nfrags + sglists);
skb_to_sgvec_nomark(skb, sg, 0, skb->len);
err = skb_to_sgvec_nomark(skb, sg, 0, skb->len);
if (unlikely(err < 0))
goto out_free;

if (x->props.flags & XFRM_STATE_ESN) {
/* Attach seqhi sg right after packet payload */
Expand Down
12 changes: 8 additions & 4 deletions net/ipv4/esp4.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,11 @@ static int esp_output(struct xfrm_state *x, struct sk_buff *skb)
esph->seq_no = htonl(XFRM_SKB_CB(skb)->seq.output.low);

sg_init_table(sg, nfrags);
skb_to_sgvec(skb, sg,
esph->enc_data + crypto_aead_ivsize(aead) - skb->data,
clen + alen);
err = skb_to_sgvec(skb, sg,
esph->enc_data + crypto_aead_ivsize(aead) - skb->data,
clen + alen);
if (unlikely(err < 0))
goto error;

if ((x->props.flags & XFRM_STATE_ESN)) {
sg_init_table(asg, 3);
Expand Down Expand Up @@ -426,7 +428,9 @@ static int esp_input(struct xfrm_state *x, struct sk_buff *skb)
iv = esph->enc_data;

sg_init_table(sg, nfrags);
skb_to_sgvec(skb, sg, sizeof(*esph) + crypto_aead_ivsize(aead), elen);
err = skb_to_sgvec(skb, sg, sizeof(*esph) + crypto_aead_ivsize(aead), elen);
if (unlikely(err < 0))
goto out;

if ((x->props.flags & XFRM_STATE_ESN)) {
sg_init_table(asg, 3);
Expand Down
8 changes: 6 additions & 2 deletions net/ipv6/ah6.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,9 @@ static int ah6_output(struct xfrm_state *x, struct sk_buff *skb)
ah->seq_no = htonl(XFRM_SKB_CB(skb)->seq.output.low);

sg_init_table(sg, nfrags + sglists);
skb_to_sgvec_nomark(skb, sg, 0, skb->len);
err = skb_to_sgvec_nomark(skb, sg, 0, skb->len);
if (unlikely(err < 0))
goto out_free;

if (x->props.flags & XFRM_STATE_ESN) {
/* Attach seqhi sg right after packet payload */
Expand Down Expand Up @@ -601,7 +603,9 @@ static int ah6_input(struct xfrm_state *x, struct sk_buff *skb)
ip6h->hop_limit = 0;

sg_init_table(sg, nfrags + sglists);
skb_to_sgvec_nomark(skb, sg, 0, skb->len);
err = skb_to_sgvec_nomark(skb, sg, 0, skb->len);
if (unlikely(err < 0))
goto out_free;

if (x->props.flags & XFRM_STATE_ESN) {
/* Attach seqhi sg right after packet payload */
Expand Down
12 changes: 8 additions & 4 deletions net/ipv6/esp6.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,11 @@ static int esp6_output(struct xfrm_state *x, struct sk_buff *skb)
esph->seq_no = htonl(XFRM_SKB_CB(skb)->seq.output.low);

sg_init_table(sg, nfrags);
skb_to_sgvec(skb, sg,
esph->enc_data + crypto_aead_ivsize(aead) - skb->data,
clen + alen);
err = skb_to_sgvec(skb, sg,
esph->enc_data + crypto_aead_ivsize(aead) - skb->data,
clen + alen);
if (unlikely(err < 0))
goto error;

if ((x->props.flags & XFRM_STATE_ESN)) {
sg_init_table(asg, 3);
Expand Down Expand Up @@ -381,7 +383,9 @@ static int esp6_input(struct xfrm_state *x, struct sk_buff *skb)
iv = esph->enc_data;

sg_init_table(sg, nfrags);
skb_to_sgvec(skb, sg, sizeof(*esph) + crypto_aead_ivsize(aead), elen);
ret = skb_to_sgvec(skb, sg, sizeof(*esph) + crypto_aead_ivsize(aead), elen);
if (unlikely(ret < 0))
goto out;

if ((x->props.flags & XFRM_STATE_ESN)) {
sg_init_table(asg, 3);
Expand Down

0 comments on commit a946f4e

Please sign in to comment.