mmc: core: Add CIDs for cards to the entropy pool
authorLinus Walleij <linus.walleij@linaro.org>
Mon, 25 Apr 2022 20:54:42 +0000 (22:54 +0200)
committerUlf Hansson <ulf.hansson@linaro.org>
Tue, 26 Apr 2022 13:39:37 +0000 (15:39 +0200)
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>
drivers/mmc/core/mmc.c
drivers/mmc/core/sd.c

index 82ca62c..89cd48f 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/slab.h>
 #include <linux/stat.h>
 #include <linux/pm_runtime.h>
+#include <linux/random.h>
 #include <linux/sysfs.h>
 
 #include <linux/mmc/host.h>
@@ -71,6 +72,12 @@ static int mmc_decode_cid(struct mmc_card *card)
 {
        u32 *resp = card->raw_cid;
 
+       /*
+        * Add the raw card ID (cid) data to the entropy pool. It doesn't
+        * matter that not all of it is unique, it's just bonus entropy.
+        */
+       add_device_randomness(&card->raw_cid, sizeof(card->raw_cid));
+
        /*
         * The selection of the format here is based upon published
         * specs from sandisk and from what people have reported.
index 68df6b2..c5f1df6 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/slab.h>
 #include <linux/stat.h>
 #include <linux/pm_runtime.h>
+#include <linux/random.h>
 #include <linux/scatterlist.h>
 #include <linux/sysfs.h>
 
@@ -83,6 +84,12 @@ void mmc_decode_cid(struct mmc_card *card)
 {
        u32 *resp = card->raw_cid;
 
+       /*
+        * Add the raw card ID (cid) data to the entropy pool. It doesn't
+        * matter that not all of it is unique, it's just bonus entropy.
+        */
+       add_device_randomness(&card->raw_cid, sizeof(card->raw_cid));
+
        /*
         * SD doesn't currently have a version field so we will
         * have to assume we can parse this.