Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mmc: core: Add CIDs for cards to the entropy pool

To make the entropy pool a bit better we can toss in the
CID for eMMC and SD cards into it, usually the serial
number portion is at least unique.

This does not count as improvement of the entropy but
in practice it makes it a bit more random to mix in these
numbers.

Cc: Theodore Ts'o <tytso@mit.edu>
Acked-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20220425205442.1347837-1-linus.walleij@linaro.org
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>

authored by

Linus Walleij and committed by
Ulf Hansson
ac9d2555 23e09be2

+14
+7
drivers/mmc/core/mmc.c
··· 12 12 #include <linux/slab.h> 13 13 #include <linux/stat.h> 14 14 #include <linux/pm_runtime.h> 15 + #include <linux/random.h> 15 16 #include <linux/sysfs.h> 16 17 17 18 #include <linux/mmc/host.h> ··· 71 70 static int mmc_decode_cid(struct mmc_card *card) 72 71 { 73 72 u32 *resp = card->raw_cid; 73 + 74 + /* 75 + * Add the raw card ID (cid) data to the entropy pool. It doesn't 76 + * matter that not all of it is unique, it's just bonus entropy. 77 + */ 78 + add_device_randomness(&card->raw_cid, sizeof(card->raw_cid)); 74 79 75 80 /* 76 81 * The selection of the format here is based upon published
+7
drivers/mmc/core/sd.c
··· 12 12 #include <linux/slab.h> 13 13 #include <linux/stat.h> 14 14 #include <linux/pm_runtime.h> 15 + #include <linux/random.h> 15 16 #include <linux/scatterlist.h> 16 17 #include <linux/sysfs.h> 17 18 ··· 83 82 void mmc_decode_cid(struct mmc_card *card) 84 83 { 85 84 u32 *resp = card->raw_cid; 85 + 86 + /* 87 + * Add the raw card ID (cid) data to the entropy pool. It doesn't 88 + * matter that not all of it is unique, it's just bonus entropy. 89 + */ 90 + add_device_randomness(&card->raw_cid, sizeof(card->raw_cid)); 86 91 87 92 /* 88 93 * SD doesn't currently have a version field so we will