crypto: tcrypt - do not attempt to write to readonly variable
[linux-2.6.git] / crypto / ahash.c
index 28a33d0..f669822 100644 (file)
@@ -47,8 +47,11 @@ static int hash_walk_next(struct crypto_hash_walk *walk)
        walk->data = crypto_kmap(walk->pg, 0);
        walk->data += offset;
 
-       if (offset & alignmask)
-               nbytes = alignmask + 1 - (offset & alignmask);
+       if (offset & alignmask) {
+               unsigned int unaligned = alignmask + 1 - (offset & alignmask);
+               if (nbytes > unaligned)
+                       nbytes = unaligned;
+       }
 
        walk->entrylen -= nbytes;
        return nbytes;
@@ -78,7 +81,6 @@ int crypto_hash_walk_done(struct crypto_hash_walk *walk, int err)
        walk->data -= walk->offset;
 
        if (nbytes && walk->offset & alignmask && !err) {
-               walk->offset += alignmask - 1;
                walk->offset = ALIGN(walk->offset, alignmask + 1);
                walk->data += walk->offset;
 
@@ -223,7 +225,7 @@ static int ahash_op_unaligned(struct ahash_request *req,
 
        priv = kmalloc(sizeof(*priv) + ahash_align_buffer_size(ds, alignmask),
                       (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
-                      GFP_ATOMIC : GFP_ATOMIC);
+                      GFP_KERNEL : GFP_ATOMIC);
        if (!priv)
                return -ENOMEM;
 
@@ -333,7 +335,7 @@ static int ahash_def_finup(struct ahash_request *req)
 
        priv = kmalloc(sizeof(*priv) + ahash_align_buffer_size(ds, alignmask),
                       (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
-                      GFP_ATOMIC : GFP_ATOMIC);
+                      GFP_KERNEL : GFP_ATOMIC);
        if (!priv)
                return -ENOMEM;