From f70ee5ec8fc59ba2d905e6daf0d395edf6fb461d Mon Sep 17 00:00:00 2001 From: "J. Bruce Fields" Date: Wed, 21 Mar 2007 08:50:12 +1100 Subject: [PATCH 1/3] [CRYPTO] api: scatterwalk_copychunks() fails to advance through scatterlist In the loop in scatterwalk_copychunks(), if walk->offset is zero, then scatterwalk_pagedone rounds that up to the nearest page boundary: walk->offset += PAGE_SIZE - 1; walk->offset &= PAGE_MASK; which is a no-op in this case, so we don't advance to the next element of the scatterlist array: if (walk->offset >= walk->sg->offset + walk->sg->length) scatterwalk_start(walk, sg_next(walk->sg)); and we end up copying the same data twice. It appears that other callers of scatterwalk_{page}done first advance walk->offset, so I believe that's the correct thing to do here. This caused a bug in NFS when run with krb5p security, which would cause some writes to fail with permissions errors--for example, writes of less than 8 bytes (the des blocksize) at the start of a file. A git-bisect shows the bug was originally introduced by 5c64097aa0f6dc4f27718ef47ca9a12538d62860, first in 2.6.19-rc1. Signed-off-by: "J. Bruce Fields" Signed-off-by: Herbert Xu --- crypto/scatterwalk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto/scatterwalk.c b/crypto/scatterwalk.c index 35172d3f043b..a66423121773 100644 --- a/crypto/scatterwalk.c +++ b/crypto/scatterwalk.c @@ -91,6 +91,8 @@ void scatterwalk_copychunks(void *buf, struct scatter_walk *walk, memcpy_dir(buf, vaddr, len_this_page, out); scatterwalk_unmap(vaddr, out); + scatterwalk_advance(walk, nbytes); + if (nbytes == len_this_page) break; @@ -99,7 +101,5 @@ void scatterwalk_copychunks(void *buf, struct scatter_walk *walk, scatterwalk_pagedone(walk, out, 1); } - - scatterwalk_advance(walk, nbytes); } EXPORT_SYMBOL_GPL(scatterwalk_copychunks); From 58e40308f329275ccf556312a9cd788522f7c224 Mon Sep 17 00:00:00 2001 From: Johannes Schlumberger Date: Wed, 21 Mar 2007 08:55:58 +1100 Subject: [PATCH 2/3] [CRYPTO] doc: Fix typo in hash example there is a tiny bug in Documentation/crypto/api-intro.txt. The file has the following example code: struct scatterlist sg[2]; [...] if (crypto_hash_digest(&desc, &sg, 2, result)) which does not match the declaration of crypto_hash_digest() in include/linux/crypto.h. (static inline int crypto_hash_digest(struct hash_desc *desc, struct scatterlist *sg, unsigned int nbytes, u8 *out) The code in the example passes the address of a pointer (an array actually) as the second argument, while the function expects the pointer itself. I have attached a patch to fix this. Signed-off-by: Herbert Xu --- Documentation/crypto/api-intro.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/crypto/api-intro.txt b/Documentation/crypto/api-intro.txt index e41a79aa71ce..9b84b805ab75 100644 --- a/Documentation/crypto/api-intro.txt +++ b/Documentation/crypto/api-intro.txt @@ -60,7 +60,7 @@ Here's an example of how to use the API: desc.tfm = tfm; desc.flags = 0; - if (crypto_hash_digest(&desc, &sg, 2, result)) + if (crypto_hash_digest(&desc, sg, 2, result)) fail(); crypto_free_hash(tfm); From 7bc301e97b96597df967f11b9fa9cf391109893a Mon Sep 17 00:00:00 2001 From: Sebastian Siewior Date: Wed, 21 Mar 2007 08:58:43 +1100 Subject: [PATCH 3/3] [CRYPTO] tcrypt: Fix error checking for comp allocation This patch fixes loading the tcrypt module while deflate isn't available at all (isn't build). Signed-off-by: Sebastian Siewior Signed-off-by: Herbert Xu --- crypto/tcrypt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c index f5e9da319ece..8eaa5aa210b0 100644 --- a/crypto/tcrypt.c +++ b/crypto/tcrypt.c @@ -768,7 +768,7 @@ static void test_deflate(void) tv = (void *)tvmem; tfm = crypto_alloc_comp("deflate", 0, CRYPTO_ALG_ASYNC); - if (tfm == NULL) { + if (IS_ERR(tfm)) { printk("failed to load transform for deflate\n"); return; }