From: Tyler Hicks <tyhicks@canonical.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: ecryptfs@vger.kernel.org
Subject: Re: is size correct in ecryptfs_parse_packet_length()
Date: Tue, 21 Oct 2014 17:29:53 -0400 [thread overview]
Message-ID: <20141021212952.GA18270@boyd> (raw)
In-Reply-To: <20141021120435.GA19969@mwanda>
[-- Attachment #1: Type: text/plain, Size: 2963 bytes --]
Hi Dan - Thanks for taking a look at the code!
On 2014-10-21 15:04:35, Dan Carpenter wrote:
> fs/ecryptfs/keystore.c +93
> 85 /**
> 86 * ecryptfs_parse_packet_length
> 87 * @data: Pointer to memory containing length at offset
> 88 * @size: This function writes the decoded size to this memory
> 89 * address; zero on error
> 90 * @length_size: The number of bytes occupied by the encoded length
> 91 *
> 92 * Returns zero on success; non-zero on error
> 93 */
> 94 int ecryptfs_parse_packet_length(unsigned char *data, size_t *size,
> 95 size_t *length_size)
> 96 {
> 97 int rc = 0;
> 98
> 99 (*length_size) = 0;
> 100 (*size) = 0;
> 101 if (data[0] < 192) {
> 102 /* One-byte length */
> 103 (*size) = (unsigned char)data[0];
> 104 (*length_size) = 1;
> 105 } else if (data[0] < 224) {
> 106 /* Two-byte length */
> 107 (*size) = (((unsigned char)(data[0]) - 192) * 256);
> ^^^^^^^^^^^^^^^
> 108 (*size) += ((unsigned char)(data[1]) + 192);
> ^^^^^^^^^^^^^^^
> These casts are no-ops because they are "data" is an unsigned char
> pointer already. Then the value is type promoted to int, we subtract
> 192 giving a negative number and we multiply by 256 giving a slightly
> larger negative then we save it as a very large positive.
Subtracting 192 from data[0] should never result in a negative number.
We know that data[0] is greater than or equal to 192 (and less than 224)
because the previous conditional was false.
>
> I don't know this well enough to say what the intent was.
This method of specifying packet sizes came from RFC2440 "OpenPGP
Message Format" (https://tools.ietf.org/html/rfc2440#section-4.2.2).
Tyler
>
> 109 (*length_size) = 2;
> 110 } else if (data[0] == 255) {
> 111 /* If support is added, adjust ECRYPTFS_MAX_PKT_LEN_SIZE */
> 112 ecryptfs_printk(KERN_ERR, "Five-byte packet length not "
> 113 "supported\n");
> 114 rc = -EINVAL;
> 115 goto out;
> 116 } else {
> 117 ecryptfs_printk(KERN_ERR, "Error parsing packet length\n");
> 118 rc = -EINVAL;
> 119 goto out;
> 120 }
> 121 out:
> 122 return rc;
> 123 }
>
> regards,
> dan carpenter
> --
> To unsubscribe from this list: send the line "unsubscribe ecryptfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
next prev parent reply other threads:[~2014-10-21 21:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-21 12:04 is size correct in ecryptfs_parse_packet_length() Dan Carpenter
2014-10-21 21:29 ` Tyler Hicks [this message]
2014-10-22 7:58 ` Dan Carpenter
2014-10-23 14:38 ` [PATCH] eCryptfs: Remove unnecessary casts when parsing packet lengths Tyler Hicks
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=20141021212952.GA18270@boyd \
--to=tyhicks@canonical.com \
--cc=dan.carpenter@oracle.com \
--cc=ecryptfs@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.