summaryrefslogtreecommitdiffstats
path: root/drivers/md/dm-crypt.c
diff options
context:
space:
mode:
authorOndrej Kozina <okozina@redhat.com>2016-12-01 12:20:52 -0500
committerMike Snitzer <snitzer@redhat.com>2016-12-08 14:13:16 -0500
commit027c431ccfcc89f7398d9f3e9bc2eb60e6cc57ad (patch)
treecd90793a833d9db7cd3d844eaacdf997e6c86ce5 /drivers/md/dm-crypt.c
parentb446396b7482938c859bfaa42320026d158616ae (diff)
dm crypt: reject key strings containing whitespace chars
Unfortunately key_string may theoretically contain whitespace even after it's processed by dm_split_args(). The reason for this is DM core supports escaping of almost all chars including any whitespace. If userspace passes a key to the kernel in format ":32:logon:my_prefix:my\ key" dm-crypt will look up key "my_prefix:my key" in kernel keyring service. So far everything's fine. Unfortunately if userspace later calls DM_TABLE_STATUS ioctl, it will not receive back expected ":32:logon:my_prefix:my\ key" but the unescaped version instead. Also userpace (most notably cryptsetup) is not ready to parse single target argument containing (even escaped) whitespace chars and any whitespace is simply taken as delimiter of another argument. This effect is mitigated by the fact libdevmapper curently performs double escaping of '\' char. Any user input in format "x\ x" is transformed into "x\\ x" before being passed to the kernel. Nonetheless dm-crypt may be used without libdevmapper. Therefore the near-term solution to this is to reject any key string containing whitespace. Signed-off-by: Ondrej Kozina <okozina@redhat.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Diffstat (limited to 'drivers/md/dm-crypt.c')
-rw-r--r--drivers/md/dm-crypt.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index da0b2e05fdf1..9b99ee9a8690 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -24,6 +24,7 @@
24#include <linux/atomic.h> 24#include <linux/atomic.h>
25#include <linux/scatterlist.h> 25#include <linux/scatterlist.h>
26#include <linux/rbtree.h> 26#include <linux/rbtree.h>
27#include <linux/ctype.h>
27#include <asm/page.h> 28#include <asm/page.h>
28#include <asm/unaligned.h> 29#include <asm/unaligned.h>
29#include <crypto/hash.h> 30#include <crypto/hash.h>
@@ -1489,6 +1490,14 @@ static int crypt_setkey(struct crypt_config *cc)
1489 1490
1490#ifdef CONFIG_KEYS 1491#ifdef CONFIG_KEYS
1491 1492
1493static bool contains_whitespace(const char *str)
1494{
1495 while (*str)
1496 if (isspace(*str++))
1497 return true;
1498 return false;
1499}
1500
1492static int crypt_set_keyring_key(struct crypt_config *cc, const char *key_string) 1501static int crypt_set_keyring_key(struct crypt_config *cc, const char *key_string)
1493{ 1502{
1494 char *new_key_string, *key_desc; 1503 char *new_key_string, *key_desc;
@@ -1496,6 +1505,15 @@ static int crypt_set_keyring_key(struct crypt_config *cc, const char *key_string
1496 struct key *key; 1505 struct key *key;
1497 const struct user_key_payload *ukp; 1506 const struct user_key_payload *ukp;
1498 1507
1508 /*
1509 * Reject key_string with whitespace. dm core currently lacks code for
1510 * proper whitespace escaping in arguments on DM_TABLE_STATUS path.
1511 */
1512 if (contains_whitespace(key_string)) {
1513 DMERR("whitespace chars not allowed in key string");
1514 return -EINVAL;
1515 }
1516
1499 /* look for next ':' separating key_type from key_description */ 1517 /* look for next ':' separating key_type from key_description */
1500 key_desc = strpbrk(key_string, ":"); 1518 key_desc = strpbrk(key_string, ":");
1501 if (!key_desc || key_desc == key_string || !strlen(key_desc + 1)) 1519 if (!key_desc || key_desc == key_string || !strlen(key_desc + 1))