Skip to content

Commit ac9d255

Browse files
Linus WalleijUlf Hansson
authored andcommitted
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>
1 parent 23e09be commit ac9d255

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

drivers/mmc/core/mmc.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/slab.h>
1313
#include <linux/stat.h>
1414
#include <linux/pm_runtime.h>
15+
#include <linux/random.h>
1516
#include <linux/sysfs.h>
1617

1718
#include <linux/mmc/host.h>
@@ -71,6 +72,12 @@ static int mmc_decode_cid(struct mmc_card *card)
7172
{
7273
u32 *resp = card->raw_cid;
7374

75+
/*
76+
* Add the raw card ID (cid) data to the entropy pool. It doesn't
77+
* matter that not all of it is unique, it's just bonus entropy.
78+
*/
79+
add_device_randomness(&card->raw_cid, sizeof(card->raw_cid));
80+
7481
/*
7582
* The selection of the format here is based upon published
7683
* specs from sandisk and from what people have reported.

drivers/mmc/core/sd.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/slab.h>
1313
#include <linux/stat.h>
1414
#include <linux/pm_runtime.h>
15+
#include <linux/random.h>
1516
#include <linux/scatterlist.h>
1617
#include <linux/sysfs.h>
1718

@@ -83,6 +84,12 @@ void mmc_decode_cid(struct mmc_card *card)
8384
{
8485
u32 *resp = card->raw_cid;
8586

87+
/*
88+
* Add the raw card ID (cid) data to the entropy pool. It doesn't
89+
* matter that not all of it is unique, it's just bonus entropy.
90+
*/
91+
add_device_randomness(&card->raw_cid, sizeof(card->raw_cid));
92+
8693
/*
8794
* SD doesn't currently have a version field so we will
8895
* have to assume we can parse this.

0 commit comments

Comments
 (0)