mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@kernel.org
Cc: stable-review@kernel.org, torvalds@linux-foundation.org,
	akpm@linux-foundation.org, alan@lxorguk.ukuu.org.uk,
	Tyler Hicks <tyhicks@linux.vnet.ibm.com>
Subject: [38/91] eCryptfs: Allow 2 scatterlist entries for encrypted
Date: Wed, 15 Jun 2011 17:15:35 -0700	[thread overview]
Message-ID: <20110616001613.051560874@clark.kroah.org> (raw)
In-Reply-To: <20110616001900.GA25375@kroah.com>

2.6.32-longterm review patch.  If anyone has any objections, please let us know.

------------------
 filenames

From: Tyler Hicks <tyhicks@linux.vnet.ibm.com>

commit 8d08dab786ad5cc2aca2bf870de370144b78c85a upstream.

The buffers allocated while encrypting and decrypting long filenames can
sometimes straddle two pages. In this situation, virt_to_scatterlist()
will return -ENOMEM, causing the operation to fail and the user will get
scary error messages in their logs:

kernel: ecryptfs_write_tag_70_packet: Internal error whilst attempting
to convert filename memory to scatterlist; expected rc = 1; got rc =
[-12]. block_aligned_filename_size = [272]
kernel: ecryptfs_encrypt_filename: Error attempting to generate tag 70
packet; rc = [-12]
kernel: ecryptfs_encrypt_and_encode_filename: Error attempting to
encrypt filename; rc = [-12]
kernel: ecryptfs_lookup: Error attempting to encrypt and encode
filename; rc = [-12]

The solution is to allow up to 2 scatterlist entries to be used.

Signed-off-by: Tyler Hicks <tyhicks@linux.vnet.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 fs/ecryptfs/keystore.c |   46 +++++++++++++++++++++-------------------------
 1 file changed, 21 insertions(+), 25 deletions(-)

--- a/fs/ecryptfs/keystore.c
+++ b/fs/ecryptfs/keystore.c
@@ -481,8 +481,8 @@ struct ecryptfs_write_tag_70_packet_sill
 	struct mutex *tfm_mutex;
 	char *block_aligned_filename;
 	struct ecryptfs_auth_tok *auth_tok;
-	struct scatterlist src_sg;
-	struct scatterlist dst_sg;
+	struct scatterlist src_sg[2];
+	struct scatterlist dst_sg[2];
 	struct blkcipher_desc desc;
 	char iv[ECRYPTFS_MAX_IV_BYTES];
 	char hash[ECRYPTFS_TAG_70_DIGEST_SIZE];
@@ -695,23 +695,21 @@ ecryptfs_write_tag_70_packet(char *dest,
 	memcpy(&s->block_aligned_filename[s->num_rand_bytes], filename,
 	       filename_size);
 	rc = virt_to_scatterlist(s->block_aligned_filename,
-				 s->block_aligned_filename_size, &s->src_sg, 1);
-	if (rc != 1) {
+				 s->block_aligned_filename_size, s->src_sg, 2);
+	if (rc < 1) {
 		printk(KERN_ERR "%s: Internal error whilst attempting to "
-		       "convert filename memory to scatterlist; "
-		       "expected rc = 1; got rc = [%d]. "
+		       "convert filename memory to scatterlist; rc = [%d]. "
 		       "block_aligned_filename_size = [%zd]\n", __func__, rc,
 		       s->block_aligned_filename_size);
 		goto out_release_free_unlock;
 	}
 	rc = virt_to_scatterlist(&dest[s->i], s->block_aligned_filename_size,
-				 &s->dst_sg, 1);
-	if (rc != 1) {
+				 s->dst_sg, 2);
+	if (rc < 1) {
 		printk(KERN_ERR "%s: Internal error whilst attempting to "
 		       "convert encrypted filename memory to scatterlist; "
-		       "expected rc = 1; got rc = [%d]. "
-		       "block_aligned_filename_size = [%zd]\n", __func__, rc,
-		       s->block_aligned_filename_size);
+		       "rc = [%d]. block_aligned_filename_size = [%zd]\n",
+		       __func__, rc, s->block_aligned_filename_size);
 		goto out_release_free_unlock;
 	}
 	/* The characters in the first block effectively do the job
@@ -734,7 +732,7 @@ ecryptfs_write_tag_70_packet(char *dest,
 		       mount_crypt_stat->global_default_fn_cipher_key_bytes);
 		goto out_release_free_unlock;
 	}
-	rc = crypto_blkcipher_encrypt_iv(&s->desc, &s->dst_sg, &s->src_sg,
+	rc = crypto_blkcipher_encrypt_iv(&s->desc, s->dst_sg, s->src_sg,
 					 s->block_aligned_filename_size);
 	if (rc) {
 		printk(KERN_ERR "%s: Error attempting to encrypt filename; "
@@ -766,8 +764,8 @@ struct ecryptfs_parse_tag_70_packet_sill
 	struct mutex *tfm_mutex;
 	char *decrypted_filename;
 	struct ecryptfs_auth_tok *auth_tok;
-	struct scatterlist src_sg;
-	struct scatterlist dst_sg;
+	struct scatterlist src_sg[2];
+	struct scatterlist dst_sg[2];
 	struct blkcipher_desc desc;
 	char fnek_sig_hex[ECRYPTFS_SIG_SIZE_HEX + 1];
 	char iv[ECRYPTFS_MAX_IV_BYTES];
@@ -872,13 +870,12 @@ ecryptfs_parse_tag_70_packet(char **file
 	}
 	mutex_lock(s->tfm_mutex);
 	rc = virt_to_scatterlist(&data[(*packet_size)],
-				 s->block_aligned_filename_size, &s->src_sg, 1);
-	if (rc != 1) {
+				 s->block_aligned_filename_size, s->src_sg, 2);
+	if (rc < 1) {
 		printk(KERN_ERR "%s: Internal error whilst attempting to "
 		       "convert encrypted filename memory to scatterlist; "
-		       "expected rc = 1; got rc = [%d]. "
-		       "block_aligned_filename_size = [%zd]\n", __func__, rc,
-		       s->block_aligned_filename_size);
+		       "rc = [%d]. block_aligned_filename_size = [%zd]\n",
+		       __func__, rc, s->block_aligned_filename_size);
 		goto out_unlock;
 	}
 	(*packet_size) += s->block_aligned_filename_size;
@@ -892,13 +889,12 @@ ecryptfs_parse_tag_70_packet(char **file
 		goto out_unlock;
 	}
 	rc = virt_to_scatterlist(s->decrypted_filename,
-				 s->block_aligned_filename_size, &s->dst_sg, 1);
-	if (rc != 1) {
+				 s->block_aligned_filename_size, s->dst_sg, 2);
+	if (rc < 1) {
 		printk(KERN_ERR "%s: Internal error whilst attempting to "
 		       "convert decrypted filename memory to scatterlist; "
-		       "expected rc = 1; got rc = [%d]. "
-		       "block_aligned_filename_size = [%zd]\n", __func__, rc,
-		       s->block_aligned_filename_size);
+		       "rc = [%d]. block_aligned_filename_size = [%zd]\n",
+		       __func__, rc, s->block_aligned_filename_size);
 		goto out_free_unlock;
 	}
 	/* The characters in the first block effectively do the job of
@@ -937,7 +933,7 @@ ecryptfs_parse_tag_70_packet(char **file
 		       mount_crypt_stat->global_default_fn_cipher_key_bytes);
 		goto out_free_unlock;
 	}
-	rc = crypto_blkcipher_decrypt_iv(&s->desc, &s->dst_sg, &s->src_sg,
+	rc = crypto_blkcipher_decrypt_iv(&s->desc, s->dst_sg, s->src_sg,
 					 s->block_aligned_filename_size);
 	if (rc) {
 		printk(KERN_ERR "%s: Error attempting to decrypt filename; "



  parent reply	other threads:[~2011-06-16  7:08 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-16  0:19 [00/91] 2.6.32.42-longterm review Greg KH
2011-06-16  0:14 ` [01/91] ftrace: Only update the function code on write to filter files Greg KH
2011-06-16  0:14 ` [02/91] kmemleak: Do not return a pointer to an object that kmemleak did not get Greg KH
2011-06-16  0:15 ` [03/91] [CPUFREQ] CPU hotplug, re-create sysfs directory and symlinks Greg KH
2011-06-16  0:15 ` [04/91] [CPUFREQ] Fix memory leak in cpufreq_stat Greg KH
2011-06-16  0:15 ` [05/91] powerpc/kexec: Fix memory corruption from unallocated slaves Greg KH
2011-06-16  0:15 ` [06/91] powerpc/oprofile: Handle events that raise an exception without overflowing Greg KH
2011-06-16  0:15 ` [07/91] block: rescan partitions on invalidated devices on -ENOMEDIA Greg KH
2011-06-16  0:15 ` [08/91] block: add proper state guards to __elv_next_request Greg KH
2011-06-16  0:15 ` [09/91] mtd: mtdconcat: fix NAND OOB write Greg KH
2011-06-16  0:15 ` [10/91] x86, 64-bit: Fix copy_[to/from]_user() checks for the Greg KH
2011-06-16  0:15 ` [11/91] ext3: Fix fs corruption when make_indexed_dir() fails Greg KH
2011-06-16  0:15 ` [12/91] jbd: Fix forever sleeping process in do_get_write_access() Greg KH
2011-06-16  0:15 ` [13/91] jbd: fix fsync() tid wraparound bug Greg KH
2011-06-16  0:15 ` [14/91] ext4: release page cache in ext4_mb_load_buddy error path Greg KH
2011-06-16  0:15 ` [15/91] [SCSI] Fix Ultrastor asm snippet Greg KH
2011-06-16  0:15 ` [16/91] x86, amd: Do not enable ARAT feature on AMD processors below Greg KH
2011-06-16  0:15 ` [17/91] x86, amd: Use _safe() msr access for GartTlbWlk disable code Greg KH
2011-06-16  0:15 ` [18/91] rcu: Fix unpaired rcu_irq_enter() from locking selftests Greg KH
2011-06-16  0:15 ` [19/91] staging: usbip: fix wrong endian conversion Greg KH
2011-06-16  0:15 ` [20/91] Fix for buffer overflow in ldm_frag_add not sufficient Greg KH
2011-06-16  0:15 ` [21/91] seqlock: Dont smp_rmb in seqlock reader spin loop Greg KH
2011-06-16  0:15 ` [22/91] ALSA: HDA: Use one dmic only for Dell Studio 1558 Greg KH
2011-06-16  0:15 ` [23/91] ASoC: Ensure output PGA is enabled for line outputs in Greg KH
2011-06-16  0:15 ` [24/91] ASoC: Add some missing volume update bit sets for wm_hubs Greg KH
2011-06-16  0:15 ` [25/91] mm/page_alloc.c: prevent unending loop in Greg KH
2011-06-16  0:15 ` [26/91] PCI: allow matching of prefetchable resources to Greg KH
2011-06-16  0:15 ` [27/91] loop: limit max_part module param to DISK_MAX_PARTS Greg KH
2011-06-16  0:15 ` [28/91] loop: handle on-demand devices correctly Greg KH
2011-06-16  0:15 ` [29/91] USB: CP210x Add 4 Device IDs for AC-Services Devices Greg KH
2011-06-16  0:15 ` [30/91] USB: moto_modem: Add USB identifier for the Motorola VE240 Greg KH
2011-06-16  0:15 ` [31/91] USB: serial: ftdi_sio: adding support for TavIR STK500 Greg KH
2011-06-16  0:15 ` [32/91] USB: gamin_gps: Fix for data transfer problems in native Greg KH
2011-06-16  0:15 ` [33/91] usb/gadget: at91sam9g20 fix end point max packet size Greg KH
2011-06-16  0:15 ` [34/91] usb: gadget: rndis: dont test against req->length Greg KH
2011-06-16  0:15 ` [35/91] xhci: Fix full speed bInterval encoding Greg KH
2011-06-16  0:15 ` [36/91] OHCI: fix regression caused by nVidia shutdown workaround Greg KH
2011-06-16  0:15 ` [37/91] p54usb: add zoom 4410 usbid Greg KH
2011-06-16  0:15 ` Greg KH [this message]
2011-06-16  0:15 ` [39/91] UBIFS: fix a rare memory leak in ro to rw remounting path Greg KH
2011-06-16  0:15 ` [40/91] i8k: Avoid lahf in 64-bit code Greg KH
2011-06-16  0:15 ` [53/91] UBIFS: fix shrinker object count reports Greg KH
2011-06-16  0:15 ` [54/91] UBIFS: fix memory leak on error path Greg KH
2011-06-16  0:15 ` [55/91] nbd: limit module parameters to a sane value Greg KH
2011-06-17 20:36 ` [Stable-review] [00/91] 2.6.32.42-longterm review Nikola Ciprich
2011-06-20 22:28   ` Greg KH

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=20110616001613.051560874@clark.kroah.org \
    --to=gregkh@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable-review@kernel.org \
    --cc=stable@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=tyhicks@linux.vnet.ibm.com \
    /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

all inboxes | Powered by JetHome®