From: Dominik Paulus <dominik@d-paulus.de>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Dominik Paulus <dominik.paulus@fau.de>,
usbip-devel@lists.sourceforge.net,
Anthony Foiani <anthony.foiani@gmail.com>,
devel@driverdev.osuosl.org, linux-kernel@i4.cs.fau.de,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-usb@vger.kernel.org,
Kurt Kanzenbach <ly80toro@cip.cs.fau.de>,
Tobias Polzer <tobias.polzer@fau.de>,
Harvey Yang <harvey.huawei.yang@gmail.com>,
linux-kernel@vger.kernel.org,
Ilija Hadzic <ihadzic@research.bell-labs.com>,
Bart Westgeest <bart@elbrys.com>, Joe Perches <joe@perches.com>,
Jake Champlin <jake.champlin.27@gmail.com>,
Stefan Reif <ke42caxa@cip.cs.fau.de>,
Bernard Blackham <b-linuxgit@largestprime.net>
Subject: Re: [PATCH 5/7] staging: usbip: Add encryption support to kernel
Date: Thu, 26 Sep 2013 12:18:34 +0200 [thread overview]
Message-ID: <20130926101833.GA8677@d-paulus.de> (raw)
In-Reply-To: <20130923105842.GH6192@mwanda> <20130923103504.GG6192@mwanda> <20130923095929.GF6192@mwanda>
Hi,
thank you very much for your feedback!
On Mon, Sep 23, 2013 at 12:59:29PM +0300, Dan Carpenter wrote:
> > + while (total < size) {
> > + uint32_t packetsize;
> > + struct kvec recvvec;
> > +
> > + /*
> > + * We use a global kfifo to buffer unrequested plaintext bytes.
> > + * Flush this buffer first before receiving new data.
> > + */
> > + if (kfifo_len(&ud->recv_queue)) {
> > + size_t next = min_t(size_t, kfifo_len(&ud->recv_queue),
> > + size - total);
> > + /* No error checking necessary - see previous line */
> > + ret = kfifo_out(&ud->recv_queue, ((char *)
> > + vec[0].iov_base)+total, next);
>
>
> The comment assume there is only one reader and one writer at a time,
> yes? The casting is not needed:
Actually, we have not only one reader and one writer, but exactly one
thread doing all the work on the fifo. No parallel access is done at
all.
> ret = kfifo_out(&ud->recv_queue,
> vec[0].iov_base + total, next);
>
>
> v> + total += next;
> > + continue;
> > + }
> > +
> > + /* See usbip_sendmsg() for the format of one encrypted packet */
> > +
> > + /*
> > + * Receive size of next crypto packet
> > + */
> > + recvvec.iov_base = &packetsize;
> > + recvvec.iov_len = sizeof(packetsize);
> > +
> > + ret = kernel_recvmsg(ud->tcp_socket, msg, &recvvec, 1,
> > + sizeof(packetsize), flags);
> > + packetsize = be32_to_cpu(packetsize);
> > + if (ret <= 0) {
>
> I think a return of zero should mean total = -EBADMSG;. In other words
> this check should be "if (ret < 0) {" and we hit the next else if.
> Same below again.
As we are wrapping kernel_recvmsg here, we wanted to leave the semantics
intact as far as possible. The calling code already checks for the correct
size.
> > + total = ret;
> > + goto err;
> > + } else if (ret != sizeof(packetsize)) {
> > + total = -EBADMSG;
> > + goto err;
> > + }
On Mon, Sep 23, 2013 at 01:35:04PM +0300, Dan Carpenter wrote:
> On Thu, Sep 19, 2013 at 04:11:57PM +0200, Dominik Paulus wrote:
> > + 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.
Indeed, that was horribly broken. Thanks.
On Mon, Sep 23, 2013 at 01:58:42PM +0300, Dan Carpenter wrote:
> On Thu, Sep 19, 2013 at 04:11:57PM +0200, Dominik Paulus wrote:
> > +{
> > + struct crypto_aead *tfm;
> > + struct aead_request *req;
> > + struct tcrypt_result result;
> > + struct scatterlist plain, cipher, assoc;
> > + char iv[16];
> > + u64 *iv_num;
> > + u64 iv_net;
> > + const int plainsize = packetsize - USBIP_AUTHSIZE;
>
> Is it possible that packetsize is less than USBIP_AUTHSIZE?
No, currently, the caller (usbip_sendmsg() / usbip_recvmsg() are the
only functions calling usbip_crypt(), which itself is static) ensures
this.
Admittedly, this isn't great design. We added a check for packetsize <
USBIP_AUTHSIZE and an appropiate return here.
> > + if (encrypt)
> > + ret = crypto_aead_encrypt(req);
> > + else
> > + ret = crypto_aead_decrypt(req);
> > +
>
> Good on you for figuring out what crypto_aead_en/decrypt() returns.
> Where are these functions documented?
>
> > + switch (ret) {
> > + case 0: /* Success */
> > + break;
> > + case -EINPROGRESS:
> > + case -EBUSY:
> > + wait_for_completion(&result.completion);
> > + break;
> > + default:
> > + aead_request_free(req);
> > + return ret;
> > + }
> > +
They aren't, actually. Documentation/crypto/api-intro.txt refers to the
regression test module, which uses exactly those return-values in
crypto/testmgr.c.
We noticed that wait_for_completion might not be the best idea, since it could
hang indefinitely, testmgr.c uses wait_for_completion_interruptible. Do we
want 'interruptible' or 'killable' here?
(Also we forgot to error-check result.err afterwards. We also fixed that.)
Regards,
Dominik Paulus, Tobias Polzer
next prev parent reply other threads:[~2013-09-26 10:18 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-19 14:11 [PATCH 0/7] staging: usbip: Extend crypto support Dominik Paulus
2013-09-19 14:11 ` [PATCH 1/7] staging: usbip: TLS for all userspace communication Dominik Paulus
2013-09-19 14:11 ` [PATCH 2/7] staging: usbip: Exchange session keys in userspace Dominik Paulus
2013-09-19 14:11 ` [PATCH 3/7] staging: usbip: Pass session keys to the kernel Dominik Paulus
2013-09-19 14:11 ` [PATCH 4/7] staging: usbip: Wrap kernel_sendmsg()/recvmsg() Dominik Paulus
2013-09-19 14:11 ` [PATCH 5/7] staging: usbip: Add encryption support to kernel Dominik Paulus
2013-09-23 9:59 ` Dan Carpenter
2013-09-26 10:18 ` Dominik Paulus [this message]
2013-09-26 11:48 ` Dan Carpenter
2013-09-23 10:35 ` Dan Carpenter
2013-09-23 10:58 ` Dan Carpenter
2013-09-19 14:11 ` [PATCH 6/7] staging: usbip: Update documentation Dominik Paulus
2013-09-19 14:11 ` [PATCH 7/7] staging: usbip: Increment version number to 1.2.1 Dominik Paulus
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130926101833.GA8677@d-paulus.de \
--to=dominik@d-paulus.de \
--cc=anthony.foiani@gmail.com \
--cc=b-linuxgit@largestprime.net \
--cc=bart@elbrys.com \
--cc=dan.carpenter@oracle.com \
--cc=devel@driverdev.osuosl.org \
--cc=dominik.paulus@fau.de \
--cc=gregkh@linuxfoundation.org \
--cc=harvey.huawei.yang@gmail.com \
--cc=ihadzic@research.bell-labs.com \
--cc=jake.champlin.27@gmail.com \
--cc=joe@perches.com \
--cc=ke42caxa@cip.cs.fau.de \
--cc=linux-kernel@i4.cs.fau.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=ly80toro@cip.cs.fau.de \
--cc=tobias.polzer@fau.de \
--cc=usbip-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox