Re: [PATCH 5/7] staging: usbip: Add encryption support to kernel

From: Dan Carpenter
Date: Mon Sep 23 2013 - 06:36:27 EST


On Thu, Sep 19, 2013 at 04:11:57PM +0200, Dominik Paulus wrote:
> +int usbip_init_crypto(struct usbip_device *ud, unsigned char *sendkey, unsigned
> + char *recvkey)
> +{
> + int ret;
> +
> + ud->use_crypto = 1;
> +
> + ud->tfm_recv = crypto_alloc_aead("gcm(aes)", 0, 0);
> + if (IS_ERR(ud->tfm_recv))
> + return -PTR_ERR(ud->tfm_recv);
> + ud->tfm_send = crypto_alloc_aead("gcm(aes)", 0, 0);
> + if (IS_ERR(ud->tfm_send)) {
> + crypto_free_aead(ud->tfm_recv);
> + return -PTR_ERR(ud->tfm_send);
> + }
> + ret = kfifo_alloc(&ud->recv_queue, RECVQ_SIZE, GFP_KERNEL);
> + if (ret) {
> + crypto_free_aead(ud->tfm_recv);
> + crypto_free_aead(ud->tfm_send);
> + return ret;
> + }
> +
> + if (crypto_aead_setkey(ud->tfm_send, sendkey, USBIP_KEYSIZE) != 0 ||
> + crypto_aead_setkey(ud->tfm_recv, recvkey,
> + USBIP_KEYSIZE) != 0 ||
> + crypto_aead_setauthsize(ud->tfm_send,
> + USBIP_AUTHSIZE) != 0 ||
> + crypto_aead_setauthsize(ud->tfm_recv,
> + USBIP_AUTHSIZE)) {
> + crypto_free_aead(ud->tfm_recv);
> + crypto_free_aead(ud->tfm_send);
> + kfifo_free(&ud->recv_queue);
> + }

This returns success on error instead of failure.

The indenting is messed up. There are three places which check " != 0"
and doesn't. Please leave off the "!= 0" throughout the whole patch.
It should look like:

if (crypto_aead_setkey(ud->tfm_send, sendkey, USBIP_KEYSIZE) ||
crypto_aead_setkey(ud->tfm_recv, recvkey, USBIP_KEYSIZE) ||
crypto_aead_setauthsize(ud->tfm_send, USBIP_AUTHSIZE) ||
crypto_aead_setauthsize(ud->tfm_recv, USBIP_AUTHSIZE)) {
ret = -EINVAL;
goto err_free_fifo;
}

Notice how the label name is chosen based on the label location and not
the goto location.

The end of the function should look like:

return 0;

err_free_fifo:
kfifo_free(&ud->recv_queue);
err_free_send:
crypto_free_aead(ud->tfm_send);
err_free_recv:
crypto_free_aead(ud->tfm_recv);

return ret;

regards,
dan carpenter

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/