2014-08-25 09:50:06

by Ondrej Kozina

[permalink] [raw]
Subject: [PATCH] avoid excessive use of socket buffer in skcipher

Hello all,

I found this bug when I ran cryptsetup testsuite on ppc64 arch. I don't have deep
insight into networking, but it seemed to me the MAX_SGL_ENTS define doesn't have
to be tied to PAGE_SIZE. Please take this patch as base for discussion, if it's
fundamentally wrong.

The 'easy' way is to increase net.core.optmem_max, but this way we would blow up
the memory overhead for every socket in kernel. Not to mention that for user space,
without not insignificant debugging effort, it's not clear what really happened.

Kind regards
Ondrej

Ondrej Kozina (1):
avoid excessive use of socket buffer in skcipher

crypto/algif_skcipher.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

--
1.9.3


2014-08-25 09:50:07

by Ondrej Kozina

[permalink] [raw]
Subject: [PATCH] avoid excessive use of socket buffer in skcipher

On archs with PAGE_SIZE >= 64 KiB the function skcipher_alloc_sgl()
fails with -ENOMEM no matter what user space actually requested.
This is caused by the fact sock_kmalloc call inside the function tried
to allocate more memory than allowed by the default kernel socket buffer
size (kernel param net.core.optmem_max).

Signed-off-by: Ondrej Kozina <[email protected]>
---
crypto/algif_skcipher.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c
index a19c027..83187f4 100644
--- a/crypto/algif_skcipher.c
+++ b/crypto/algif_skcipher.c
@@ -49,7 +49,7 @@ struct skcipher_ctx {
struct ablkcipher_request req;
};

-#define MAX_SGL_ENTS ((PAGE_SIZE - sizeof(struct skcipher_sg_list)) / \
+#define MAX_SGL_ENTS ((4096 - sizeof(struct skcipher_sg_list)) / \
sizeof(struct scatterlist) - 1)

static inline int skcipher_sndbuf(struct sock *sk)
--
1.9.3

2014-09-01 15:22:53

by Ondrej Kozina

[permalink] [raw]
Subject: Re: [PATCH] avoid excessive use of socket buffer in skcipher

Attaching simple reproducer.

Kind regards
Ondrej



Attachments:
reproducer_ppc64.c (2.82 kB)

2014-09-01 15:42:17

by Ondrej Kozina

[permalink] [raw]
Subject: Re: [PATCH] avoid excessive use of socket buffer in skcipher

On 09/01/2014 05:22 PM, Ondrej Kozina wrote:
> Attaching simple reproducer.

Sigh. Mondays... Sending fixed reproducer. Excuse my mistake.

Kind regards
Ondrej


Attachments:
reproducer_ppc64.c (2.82 kB)

2014-09-04 07:09:01

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH] avoid excessive use of socket buffer in skcipher

On Mon, Aug 25, 2014 at 11:49:54AM +0200, Ondrej Kozina wrote:
> On archs with PAGE_SIZE >= 64 KiB the function skcipher_alloc_sgl()
> fails with -ENOMEM no matter what user space actually requested.
> This is caused by the fact sock_kmalloc call inside the function tried
> to allocate more memory than allowed by the default kernel socket buffer
> size (kernel param net.core.optmem_max).
>
> Signed-off-by: Ondrej Kozina <[email protected]>

Patch applied. Thanks!
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

2014-11-08 08:44:06

by Milan Broz

[permalink] [raw]
Subject: Re: [PATCH] avoid excessive use of socket buffer in skcipher

On 09/04/2014 09:08 AM, Herbert Xu wrote:
> On Mon, Aug 25, 2014 at 11:49:54AM +0200, Ondrej Kozina wrote:
>> On archs with PAGE_SIZE >= 64 KiB the function skcipher_alloc_sgl()
>> fails with -ENOMEM no matter what user space actually requested.
>> This is caused by the fact sock_kmalloc call inside the function tried
>> to allocate more memory than allowed by the default kernel socket buffer
>> size (kernel param net.core.optmem_max).
>>
>> Signed-off-by: Ondrej Kozina <[email protected]>
>
> Patch applied. Thanks!

Please could you send this also to stable tree?
Upstream commit now is e2cffb5f493a8b431dc87124388ea59b79f0bccb

I think it is the problem in all kernels using large page size and skcipher api.

Thanks,
Milan