Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1656971 > unrolled thread
| Started by | "Jason A. Donenfeld" <Jason@zx2c4.com> |
|---|---|
| First post | 2017-06-04 04:20 +0200 |
| Last post | 2017-06-05 05:10 +0200 |
| Articles | 3 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH net-next v10 0/5] Avoiding stack overflow in skb_to_sgvec "Jason A. Donenfeld" <Jason@zx2c4.com> - 2017-06-04 04:20 +0200
[PATCH net-next v10 3/5] rxrpc: check return value of skb_to_sgvec always "Jason A. Donenfeld" <Jason@zx2c4.com> - 2017-06-04 04:20 +0200
Re: [PATCH net-next v10 0/5] Avoiding stack overflow in skb_to_sgvec David Miller <davem@davemloft.net> - 2017-06-05 05:10 +0200
| From | "Jason A. Donenfeld" <Jason@zx2c4.com> |
|---|---|
| Date | 2017-06-04 04:20 +0200 |
| Subject | [PATCH net-next v10 0/5] Avoiding stack overflow in skb_to_sgvec |
| Message-ID | <tOtj3-6Of-3@gated-at.bofh.it> |
Changes v9->v10: - Spaces to tabs on one line. - Added some acked-by, reviewed-by lines. Since we're down to only cleaning up things like spaces-to-tabs, I believe we can merge this patch series. David - would you put this in net-next, please? 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. 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-06-04 04:20 +0200 |
| Subject | [PATCH net-next v10 3/5] rxrpc: check return value of skb_to_sgvec always |
| Message-ID | <tOtj4-6Of-19@gated-at.bofh.it> |
| In reply to | #1656971 |
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Acked-by: David Howells <dhowells@redhat.com>
---
net/rxrpc/rxkad.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
index 1bb9b2ccc267..29fe20ad04aa 100644
--- a/net/rxrpc/rxkad.c
+++ b/net/rxrpc/rxkad.c
@@ -227,7 +227,9 @@ static int rxkad_secure_packet_encrypt(const struct rxrpc_call *call,
len &= ~(call->conn->size_align - 1);
sg_init_table(sg, nsg);
- skb_to_sgvec(skb, sg, 0, len);
+ err = skb_to_sgvec(skb, sg, 0, len);
+ if (unlikely(err < 0))
+ goto out;
skcipher_request_set_crypt(req, sg, sg, len, iv.x);
crypto_skcipher_encrypt(req);
@@ -324,7 +326,7 @@ static int rxkad_verify_packet_1(struct rxrpc_call *call, struct sk_buff *skb,
bool aborted;
u32 data_size, buf;
u16 check;
- int nsg;
+ int nsg, ret;
_enter("");
@@ -342,7 +344,9 @@ static int rxkad_verify_packet_1(struct rxrpc_call *call, struct sk_buff *skb,
goto nomem;
sg_init_table(sg, nsg);
- skb_to_sgvec(skb, sg, offset, 8);
+ ret = skb_to_sgvec(skb, sg, offset, 8);
+ if (unlikely(ret < 0))
+ return ret;
/* start the decryption afresh */
memset(&iv, 0, sizeof(iv));
@@ -409,7 +413,7 @@ static int rxkad_verify_packet_2(struct rxrpc_call *call, struct sk_buff *skb,
bool aborted;
u32 data_size, buf;
u16 check;
- int nsg;
+ int nsg, ret;
_enter(",{%d}", skb->len);
@@ -434,7 +438,12 @@ static int rxkad_verify_packet_2(struct rxrpc_call *call, struct sk_buff *skb,
}
sg_init_table(sg, nsg);
- skb_to_sgvec(skb, sg, offset, len);
+ ret = skb_to_sgvec(skb, sg, offset, len);
+ if (unlikely(ret < 0)) {
+ if (sg != _sg)
+ kfree(sg);
+ return ret;
+ }
/* decrypt from the session key */
token = call->conn->params.key->payload.data[0];
--
2.13.0
[toc] | [prev] | [next] | [standalone]
| From | David Miller <davem@davemloft.net> |
|---|---|
| Date | 2017-06-05 05:10 +0200 |
| Subject | Re: [PATCH net-next v10 0/5] Avoiding stack overflow in skb_to_sgvec |
| Message-ID | <tOQyZ-5F6-3@gated-at.bofh.it> |
| In reply to | #1656971 |
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
Date: Sun, 4 Jun 2017 04:16:21 +0200
> Changes v9->v10:
> - Spaces to tabs on one line.
> - Added some acked-by, reviewed-by lines.
I wish in the future you would retain the entire change history, and
keep it in it's entirety here in the header postings. That list of
adjustments is important and might be useful to someone in the future
("why didn't they do this, oh they decided to not do that
intentionally I can see that in the Change list").
> 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.
Applied to net-next.
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web