Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1648237 > unrolled thread
| Started by | "Jason A. Donenfeld" <Jason@zx2c4.com> |
|---|---|
| First post | 2017-05-23 18:10 +0200 |
| Last post | 2017-05-23 18:30 +0200 |
| Articles | 9 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH net-next v9 0/5] skb_to_sgvec hardening "Jason A. Donenfeld" <Jason@zx2c4.com> - 2017-05-23 18:10 +0200
[PATCH net-next v9 5/5] virtio_net: check return value of skb_to_sgvec always "Jason A. Donenfeld" <Jason@zx2c4.com> - 2017-05-23 18:10 +0200
Re: [PATCH net-next v9 5/5] virtio_net: check return value of skb_to_sgvec always Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> - 2017-05-24 11:50 +0200
Re: [PATCH net-next v9 5/5] virtio_net: check return value of skb_to_sgvec always "Jason A. Donenfeld" <Jason@zx2c4.com> - 2017-05-24 13:40 +0200
Re: [PATCH net-next v9 5/5] virtio_net: check return value of skb_to_sgvec always Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> - 2017-05-24 18:50 +0200
Re: [PATCH net-next v9 5/5] virtio_net: check return value of skb_to_sgvec always "Jason A. Donenfeld" <Jason@zx2c4.com> - 2017-05-24 22:40 +0200
Re: [PATCH net-next v9 5/5] virtio_net: check return value of skb_to_sgvec always Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> - 2017-05-24 22:50 +0200
[PATCH net-next v9 2/5] ipsec: check return value of skb_to_sgvec always "Jason A. Donenfeld" <Jason@zx2c4.com> - 2017-05-23 18:10 +0200
Re: [PATCH net-next v9 0/5] skb_to_sgvec hardening "Jason A. Donenfeld" <Jason@zx2c4.com> - 2017-05-23 18:30 +0200
| From | "Jason A. Donenfeld" <Jason@zx2c4.com> |
|---|---|
| Date | 2017-05-23 18:10 +0200 |
| Subject | [PATCH net-next v9 0/5] skb_to_sgvec hardening |
| Message-ID | <tKkxI-5uz-13@gated-at.bofh.it> |
The recent bug with macsec and historical one with virtio have indicated that letting skb_to_sgvec trounce all over an sglist without checking the length is probably a bad idea. And it's not necessary either: an sglist already explicitly marks its last item, and the initialization functions are diligent in doing so. Thus there's a clear way of avoiding future overflows. So, this patchset, from a high level, makes skb_to_sgvec return a potential error code, and then adjusts all callers to check for the error code. There are two situations in which skb_to_sgvec might return such an error: 1) When the passed in sglist is too small; and 2) When the passed in skbuff is too deeply nested. So, the first patch in this series handles the issues with skb_to_sgvec directly, and the remaining ones then handle the call sites. Changes v8->v9: - Return correct errno in rxrpc, thanks to feedback from Dave Howells. Jason A. Donenfeld (5): skbuff: return -EMSGSIZE in skb_to_sgvec to prevent overflow ipsec: check return value of skb_to_sgvec always rxrpc: check return value of skb_to_sgvec always macsec: check return value of skb_to_sgvec always virtio_net: check return value of skb_to_sgvec always drivers/net/macsec.c | 13 ++++++++-- drivers/net/virtio_net.c | 9 +++++-- include/linux/skbuff.h | 8 +++--- net/core/skbuff.c | 65 +++++++++++++++++++++++++++++++----------------- net/ipv4/ah4.c | 8 ++++-- net/ipv4/esp4.c | 20 +++++++++------ net/ipv6/ah6.c | 8 ++++-- net/ipv6/esp6.c | 20 +++++++++------ net/rxrpc/rxkad.c | 19 ++++++++++---- 9 files changed, 116 insertions(+), 54 deletions(-) -- 2.13.0
[toc] | [next] | [standalone]
| From | "Jason A. Donenfeld" <Jason@zx2c4.com> |
|---|---|
| Date | 2017-05-23 18:10 +0200 |
| Subject | [PATCH net-next v9 5/5] virtio_net: check return value of skb_to_sgvec always |
| Message-ID | <tKkxI-5uz-31@gated-at.bofh.it> |
| In reply to | #1648237 |
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Jason Wang <jasowang@redhat.com>
---
drivers/net/virtio_net.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 9320d96a1632..13fbe4b349c2 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -1150,7 +1150,7 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb)
struct virtio_net_hdr_mrg_rxbuf *hdr;
const unsigned char *dest = ((struct ethhdr *)skb->data)->h_dest;
struct virtnet_info *vi = sq->vq->vdev->priv;
- unsigned num_sg;
+ int num_sg;
unsigned hdr_len = vi->hdr_len;
bool can_push;
@@ -1177,11 +1177,16 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb)
if (can_push) {
__skb_push(skb, hdr_len);
num_sg = skb_to_sgvec(skb, sq->sg, 0, skb->len);
+ if (unlikely(num_sg < 0))
+ return num_sg;
/* Pull header back to avoid skew in tx bytes calculations. */
__skb_pull(skb, hdr_len);
} else {
sg_set_buf(sq->sg, hdr, hdr_len);
- num_sg = skb_to_sgvec(skb, sq->sg + 1, 0, skb->len) + 1;
+ num_sg = skb_to_sgvec(skb, sq->sg + 1, 0, skb->len);
+ if (unlikely(num_sg < 0))
+ return num_sg;
+ num_sg++;
}
return virtqueue_add_outbuf(sq->vq, sq->sg, num_sg, skb, GFP_ATOMIC);
}
--
2.13.0
[toc] | [prev] | [next] | [standalone]
| From | Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> |
|---|---|
| Date | 2017-05-24 11:50 +0200 |
| Subject | Re: [PATCH net-next v9 5/5] virtio_net: check return value of skb_to_sgvec always |
| Message-ID | <tKB5w-AM-21@gated-at.bofh.it> |
| In reply to | #1648238 |
Hello!
On 5/23/2017 7:05 PM, Jason A. Donenfeld wrote:
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> Cc: "Michael S. Tsirkin" <mst@redhat.com>
> Cc: Jason Wang <jasowang@redhat.com>
> ---
> drivers/net/virtio_net.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 9320d96a1632..13fbe4b349c2 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -1150,7 +1150,7 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb)
> struct virtio_net_hdr_mrg_rxbuf *hdr;
> const unsigned char *dest = ((struct ethhdr *)skb->data)->h_dest;
> struct virtnet_info *vi = sq->vq->vdev->priv;
> - unsigned num_sg;
> + int num_sg;
> unsigned hdr_len = vi->hdr_len;
> bool can_push;
>
> @@ -1177,11 +1177,16 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb)
> if (can_push) {
> __skb_push(skb, hdr_len);
> num_sg = skb_to_sgvec(skb, sq->sg, 0, skb->len);
> + if (unlikely(num_sg < 0))
Please indent with tabs, like above and below.
> + return num_sg;
> /* Pull header back to avoid skew in tx bytes calculations. */
> __skb_pull(skb, hdr_len);
[...]
MBR, Sergei
[toc] | [prev] | [next] | [standalone]
| From | "Jason A. Donenfeld" <Jason@zx2c4.com> |
|---|---|
| Date | 2017-05-24 13:40 +0200 |
| Subject | Re: [PATCH net-next v9 5/5] virtio_net: check return value of skb_to_sgvec always |
| Message-ID | <tKCNY-1KT-15@gated-at.bofh.it> |
| In reply to | #1649387 |
I'm shocked this somehow made it into the commit. I wonder how that happened? Anyway, fixed in my git repo, and will be part of the next series. (Unless DaveM wants to fix it up trivially when/if he merges this v9, which would be faster.) Barring that, does this look good to you? Could I have your signed-off-by? Regards, Jason
[toc] | [prev] | [next] | [standalone]
| From | Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> |
|---|---|
| Date | 2017-05-24 18:50 +0200 |
| Subject | Re: [PATCH net-next v9 5/5] virtio_net: check return value of skb_to_sgvec always |
| Message-ID | <tKHDX-4Jq-21@gated-at.bofh.it> |
| In reply to | #1649507 |
On 05/24/2017 02:34 PM, Jason A. Donenfeld wrote:
> I'm shocked this somehow made it into the commit. I wonder how that happened?
Sorry for not noticing this when it first appeared.
> Anyway, fixed in my git repo, and will be part of the next series.
> (Unless DaveM wants to fix it up trivially when/if he merges this v9,
> which would be faster.)
>
> Barring that, does this look good to you? Could I have your signed-off-by?
I've only looked on the last 2 patches. You can add my:
Reviewed-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
if you want. :-)
> Regards,
> Jason
MBR, Sergei
[toc] | [prev] | [next] | [standalone]
| From | "Jason A. Donenfeld" <Jason@zx2c4.com> |
|---|---|
| Date | 2017-05-24 22:40 +0200 |
| Subject | Re: [PATCH net-next v9 5/5] virtio_net: check return value of skb_to_sgvec always |
| Message-ID | <tKLey-72S-17@gated-at.bofh.it> |
| In reply to | #1649760 |
On Wed, May 24, 2017 at 6:41 PM, Sergei Shtylyov > I've only looked on the last 2 patches. You can add my: > > Reviewed-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> > > if you want. :-) Will do. For the series, or just for 5/5?
[toc] | [prev] | [next] | [standalone]
| From | Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> |
|---|---|
| Date | 2017-05-24 22:50 +0200 |
| Subject | Re: [PATCH net-next v9 5/5] virtio_net: check return value of skb_to_sgvec always |
| Message-ID | <tKLoe-76t-27@gated-at.bofh.it> |
| In reply to | #1649936 |
On 05/24/2017 11:39 PM, Jason A. Donenfeld wrote:
>> I've only looked on the last 2 patches. You can add my:
>>
>> Reviewed-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
>>
>> if you want. :-)
>
> Will do. For the series, or just for 5/5?
5/5 only. :-)
MBR, Sergei
[toc] | [prev] | [next] | [standalone]
| From | "Jason A. Donenfeld" <Jason@zx2c4.com> |
|---|---|
| Date | 2017-05-23 18:10 +0200 |
| Subject | [PATCH net-next v9 2/5] ipsec: check return value of skb_to_sgvec always |
| Message-ID | <tKkxI-5uz-33@gated-at.bofh.it> |
| In reply to | #1648237 |
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Cc: Steffen Klassert <steffen.klassert@secunet.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: "David S. Miller" <davem@davemloft.net>
---
net/ipv4/ah4.c | 8 ++++++--
net/ipv4/esp4.c | 20 +++++++++++++-------
net/ipv6/ah6.c | 8 ++++++--
net/ipv6/esp6.c | 20 +++++++++++++-------
4 files changed, 38 insertions(+), 18 deletions(-)
diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
index 22377c8ff14b..e8f862358518 100644
--- a/net/ipv4/ah4.c
+++ b/net/ipv4/ah4.c
@@ -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 */
@@ -393,7 +395,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 */
diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
index 65cc02bd82bc..392432860bb9 100644
--- a/net/ipv4/esp4.c
+++ b/net/ipv4/esp4.c
@@ -374,9 +374,11 @@ int esp_output_tail(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *
esp->esph = esph;
sg_init_table(sg, esp->nfrags);
- skb_to_sgvec(skb, sg,
- (unsigned char *)esph - skb->data,
- assoclen + ivlen + esp->clen + alen);
+ err = skb_to_sgvec(skb, sg,
+ (unsigned char *)esph - skb->data,
+ assoclen + ivlen + esp->clen + alen);
+ if (unlikely(err < 0))
+ goto error;
if (!esp->inplace) {
int allocsize;
@@ -400,9 +402,11 @@ int esp_output_tail(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *
spin_unlock_bh(&x->lock);
sg_init_table(dsg, skb_shinfo(skb)->nr_frags + 1);
- skb_to_sgvec(skb, dsg,
- (unsigned char *)esph - skb->data,
- assoclen + ivlen + esp->clen + alen);
+ err = skb_to_sgvec(skb, dsg,
+ (unsigned char *)esph - skb->data,
+ assoclen + ivlen + esp->clen + alen);
+ if (unlikely(err < 0))
+ goto error;
}
if ((x->props.flags & XFRM_STATE_ESN))
@@ -687,7 +691,9 @@ static int esp_input(struct xfrm_state *x, struct sk_buff *skb)
esp_input_set_header(skb, seqhi);
sg_init_table(sg, nfrags);
- skb_to_sgvec(skb, sg, 0, skb->len);
+ err = skb_to_sgvec(skb, sg, 0, skb->len);
+ if (unlikely(err < 0))
+ goto out;
skb->ip_summed = CHECKSUM_NONE;
diff --git a/net/ipv6/ah6.c b/net/ipv6/ah6.c
index dda6035e3b84..755f38271dd5 100644
--- a/net/ipv6/ah6.c
+++ b/net/ipv6/ah6.c
@@ -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 */
@@ -606,7 +608,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 */
diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c
index 1fe99ba8066c..2ede4e459c4e 100644
--- a/net/ipv6/esp6.c
+++ b/net/ipv6/esp6.c
@@ -346,9 +346,11 @@ int esp6_output_tail(struct xfrm_state *x, struct sk_buff *skb, struct esp_info
esph = esp_output_set_esn(skb, x, ip_esp_hdr(skb), seqhi);
sg_init_table(sg, esp->nfrags);
- skb_to_sgvec(skb, sg,
- (unsigned char *)esph - skb->data,
- assoclen + ivlen + esp->clen + alen);
+ err = skb_to_sgvec(skb, sg,
+ (unsigned char *)esph - skb->data,
+ assoclen + ivlen + esp->clen + alen);
+ if (unlikely(err < 0))
+ goto error;
if (!esp->inplace) {
int allocsize;
@@ -372,9 +374,11 @@ int esp6_output_tail(struct xfrm_state *x, struct sk_buff *skb, struct esp_info
spin_unlock_bh(&x->lock);
sg_init_table(dsg, skb_shinfo(skb)->nr_frags + 1);
- skb_to_sgvec(skb, dsg,
- (unsigned char *)esph - skb->data,
- assoclen + ivlen + esp->clen + alen);
+ err = skb_to_sgvec(skb, dsg,
+ (unsigned char *)esph - skb->data,
+ assoclen + ivlen + esp->clen + alen);
+ if (unlikely(err < 0))
+ goto error;
}
if ((x->props.flags & XFRM_STATE_ESN))
@@ -618,7 +622,9 @@ static int esp6_input(struct xfrm_state *x, struct sk_buff *skb)
esp_input_set_header(skb, seqhi);
sg_init_table(sg, nfrags);
- skb_to_sgvec(skb, sg, 0, skb->len);
+ ret = skb_to_sgvec(skb, sg, 0, skb->len);
+ if (unlikely(ret < 0))
+ goto out;
skb->ip_summed = CHECKSUM_NONE;
--
2.13.0
[toc] | [prev] | [next] | [standalone]
| From | "Jason A. Donenfeld" <Jason@zx2c4.com> |
|---|---|
| Date | 2017-05-23 18:30 +0200 |
| Message-ID | <tKkR3-5Bx-1@gated-at.bofh.it> |
| In reply to | #1648237 |
Hi List, Could somebody do a holistic review of the series, or at least on individual commits that seem fine, and sign off on it, so that this can actually be merged? We're now at v9. I hope we can get this merged now, but if not, I'd like for v10 to finally land these changes. Regards, Jason
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web