lkml.org 
[lkml]   [2016]   [Sep]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    SubjectRe: Kernel panic - encryption/decryption failed when open file on Arm64
    From
    Date
    > On 12 September 2016 at 03:16, liushuoran <liushuoran@huawei.com> wrote:
    >> Hi Ard,
    >>
    >> Thanks for the prompt reply. With the patch, there is no panic anymore. But it seems that the encryption/decryption is not successful anyway.
    >>
    >> As Herbert points out, "If the page allocation fails in blkcipher_walk_next it'll simply switch over to processing it block by block". So does that mean the encryption/decryption should be successful even if the page allocation fails? Please correct me if I misunderstand anything. Thanks in advance.
    >>
    >
    > Perhaps Herbert can explain: I don't see how the 'n = 0' assignment
    > results in the correct path being taken; this chunk (blkcipher.c:252)
    >
    > if (unlikely(n < bsize)) {
    > err = blkcipher_next_slow(desc, walk, bsize, walk->alignmask);
    > goto set_phys_lowmem;
    > }
    >
    > is skipped due to the fact that n == 0 and therefore bsize == 0, and
    > so the condition is always false for n == 0
    >
    > Therefore we end up here (blkcipher.c:257)
    >
    > walk->nbytes = n;
    > if (walk->flags & BLKCIPHER_WALK_COPY) {
    > err = blkcipher_next_copy(walk);
    > goto set_phys_lowmem;
    > }
    >
    > where blkcipher_next_copy() unconditionally calls memcpy() with
    > walk->page as destination (even though we ended up here due to the
    > fact that walk->page == NULL)
    >
    > So to me, it seems like we should be taking the blkcipher_next_slow()
    > path, which does a kmalloc() and bails with -ENOMEM if that fails.

    Hi Ard,

    Thanks for such a detailed reply.

    According to your reply, I just make a little change to take the
    blkcipher_next_slow() path. I test it on arm64 board, there is
    no panic anymore and seems the encryption/decryption is successful.

    diff --git a/crypto/blkcipher.c b/crypto/blkcipher.c
    index 0122bec..5389d40 100644
    --- a/crypto/blkcipher.c
    +++ b/crypto/blkcipher.c
    @@ -240,12 +240,13 @@ static int blkcipher_walk_next(struct blkcipher_desc *desc,
    walk->flags |= BLKCIPHER_WALK_COPY;
    if (!walk->page) {
    walk->page = (void *)__get_free_page(GFP_ATOMIC);
    + walk->page = NULL;
    if (!walk->page)
    n = 0;
    }
    }

    - bsize = min(walk->walk_blocksize, n);
    + bsize = walk->walk_blocksize;
    n = scatterwalk_clamp(&walk->in, n);
    n = scatterwalk_clamp(&walk->out, n);

    It is just a trial and not sure it makes sense. But anyway, we can do
    something here to fix the crash result from the page allocation failure.
    What's your opinions, Herbert?

    Regards
    Kaixu Xia
    >
    > .
    >

    \
     
     \ /
      Last update: 2016-09-17 09:59    [W:5.400 / U:0.552 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site