Message ID | 20200916114502.33895-1-bage@linutronix.de |
---|---|
State | Accepted |
Headers | show |
Series | encrypted images: fix one block sized image decryption | expand |
On 16.09.20 13:45, bage@linutronix.de wrote: > From: Bastian Germann <bage@linutronix.de> > > SWUpdate has a bug in the decryption handling. For encrypted image > content that is exactly one AES block (16 bytes) of size (from an > unencrypted file of < 16 bytes), the output is empty. > > The reason for this effect is the first swupdate_DECRYPT_update writing > 0 bytes and the copyfile() implementation skipping the final decryption > step because it checks on the written bytes. > > Check swupdate_DECRYPT_update return for zero, and call > swupdate_DECRYPT_final() directly afterwards. > > Signed-off-by: Bastian Germann <bage@linutronix.de> > --- > core/cpio_utils.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/core/cpio_utils.c b/core/cpio_utils.c > index e2e857c..0ba85fd 100644 > --- a/core/cpio_utils.c > +++ b/core/cpio_utils.c > @@ -243,7 +243,8 @@ static int decrypt_step(void *state, void *buffer, size_t size) > if (inlen != 0) { > ret = swupdate_DECRYPT_update(s->dcrypt, > s->output, &s->outlen, s->input, inlen); > - } else { > + } > + if (inlen == 0 || ret == 0) { > /* > * Finalise the decryption. Further plaintext bytes may > * be written at this stage. > Tested with vlock size > 16: Tested-by: Stefano Babic <sbabic@denx.de> Best regards, Stefano Babic
diff --git a/core/cpio_utils.c b/core/cpio_utils.c index e2e857c..0ba85fd 100644 --- a/core/cpio_utils.c +++ b/core/cpio_utils.c @@ -243,7 +243,8 @@ static int decrypt_step(void *state, void *buffer, size_t size) if (inlen != 0) { ret = swupdate_DECRYPT_update(s->dcrypt, s->output, &s->outlen, s->input, inlen); - } else { + } + if (inlen == 0 || ret == 0) { /* * Finalise the decryption. Further plaintext bytes may * be written at this stage.