netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 00/11] rename random32 to prandom and introduce prandom_bytes()
@ 2012-11-13 13:36 Akinobu Mita
  2012-11-13 13:37 ` [PATCH v3 02/11] prandom: introduce prandom_bytes() and prandom_bytes_state() Akinobu Mita
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Akinobu Mita @ 2012-11-13 13:36 UTC (permalink / raw)
  To: linux-kernel, akpm
  Cc: Akinobu Mita, Theodore Ts'o, Artem Bityutskiy, Adrian Hunter,
	David Woodhouse, linux-mtd, Eilon Greenstein, netdev, Robert Love,
	devel, Michel Lespinasse

This patchset introduces new functions into random32 library for
getting the requested number of pseudo-random bytes.

Before introducing these new functions into random32 library,
rename all random32 functions to have 'prandom_' prefix.  As a result
the function prototypes are as follows:

void prandom_seed(u32 seed);	/* rename from srandom32() */
u32 prandom_u32(void);		/* rename from random32() */
void prandom_bytes(void *buf, int nbytes);

void prandom_seed_state(struct rnd_state *state, u64 seed);
				/* rename from prandom32_seed() */
u32 prandom_u32_state(struct rnd_state *state);
				/* rename from prandom32() */
void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);

The purpose of this renaming is to prevent some kernel developers
from assuming that prandom32() and random32() might imply that only
prandom32() was the one using a pseudo-random number generator by
prandom32's "p", and the result may be a very embarassing security
exposure.  This concern was expressed by Theodore Ts'o.

Changelog

* v3
- change common prefix from 'random32_' to 'prandom_'
- ensure prandom_bytes_state() generates same bytes with same rnd_state

* v2
- rename prandom32 to random32_state
- dropped lib/uuid.c patch
- add bnx2 and mtd_stresstest patches

Akinobu Mita (11):
  random32: rename random32 to prandom
  prandom: introduce prandom_bytes() and prandom_bytes_state()
  bnx2x: use prandom_bytes()
  mtd: nandsim: use prandom_bytes
  ubifs: use prandom_bytes
  mtd: mtd_nandecctest: use prandom_bytes instead of get_random_bytes()
  mtd: mtd_oobtest: convert to use prandom library
  mtd: mtd_pagetest: convert to use prandom library
  mtd: mtd_speedtest: use prandom_bytes
  mtd: mtd_subpagetest: convert to use prandom library
  mtd: mtd_stresstest: use prandom_bytes()

 drivers/mtd/nand/nandsim.c                      |  5 +-
 drivers/mtd/tests/mtd_nandecctest.c             |  2 +-
 drivers/mtd/tests/mtd_oobtest.c                 | 49 ++++---------
 drivers/mtd/tests/mtd_pagetest.c                | 43 ++++-------
 drivers/mtd/tests/mtd_speedtest.c               |  9 +--
 drivers/mtd/tests/mtd_stresstest.c              |  3 +-
 drivers/mtd/tests/mtd_subpagetest.c             | 42 +++--------
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c |  5 +-
 drivers/scsi/fcoe/fcoe_ctlr.c                   |  4 +-
 fs/ubifs/debug.c                                |  8 +-
 include/linux/random.h                          | 19 +++--
 lib/interval_tree_test_main.c                   |  7 +-
 lib/random32.c                                  | 97 +++++++++++++++++++------
 lib/rbtree_test.c                               |  6 +-
 14 files changed, 145 insertions(+), 154 deletions(-)

Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Artem Bityutskiy <dedekind1@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: linux-mtd@lists.infradead.org
Cc: Eilon Greenstein <eilong@broadcom.com>
Cc: netdev@vger.kernel.org
Cc: Robert Love <robert.w.love@intel.com>
Cc: devel@open-fcoe.org
Cc: Michel Lespinasse <walken@google.com>
-- 
1.7.11.7

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v3 02/11] prandom: introduce prandom_bytes() and prandom_bytes_state()
  2012-11-13 13:36 [PATCH v3 00/11] rename random32 to prandom and introduce prandom_bytes() Akinobu Mita
@ 2012-11-13 13:37 ` Akinobu Mita
  2012-11-13 13:37 ` [PATCH v3 03/11] bnx2x: use prandom_bytes() Akinobu Mita
  2012-11-13 19:55 ` [PATCH v3 00/11] rename random32 to prandom and introduce prandom_bytes() Andrew Morton
  2 siblings, 0 replies; 4+ messages in thread
From: Akinobu Mita @ 2012-11-13 13:37 UTC (permalink / raw)
  To: linux-kernel, akpm
  Cc: Akinobu Mita, Theodore Ts'o, Artem Bityutskiy, Adrian Hunter,
	David Woodhouse, linux-mtd, Eilon Greenstein, netdev

Add functions to get the requested number of pseudo-random bytes.

The difference from get_random_bytes() is that it generates pseudo-random
numbers by prandom_u32().  It doesn't consume the entropy pool, and the
sequence is reproducible if the same rnd_state is used.  So it is suitable
for generating random bytes for testing.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Artem Bityutskiy <dedekind1@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: linux-mtd@lists.infradead.org
Cc: Eilon Greenstein <eilong@broadcom.com>
Cc: netdev@vger.kernel.org
---
* v3
- rename random32_get_bytes_state to prandom_bytes_state
- ensure prandom_bytes_state() generates same bytes with same rnd_state

* v2
- rename prandom32_get_bytes to random32_get_bytes_state

 include/linux/random.h |  2 ++
 lib/random32.c         | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)

diff --git a/include/linux/random.h b/include/linux/random.h
index db6debc..d984608 100644
--- a/include/linux/random.h
+++ b/include/linux/random.h
@@ -26,6 +26,7 @@ unsigned int get_random_int(void);
 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
 
 u32 prandom_u32(void);
+void prandom_bytes(void *buf, int nbytes);
 void prandom_seed(u32 seed);
 
 /*
@@ -36,6 +37,7 @@ void prandom_seed(u32 seed);
 #define srandom32(seed) prandom_seed(seed)
 
 u32 prandom_u32_state(struct rnd_state *);
+void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
 
 /*
  * Handle minimum values for seeds
diff --git a/lib/random32.c b/lib/random32.c
index d1830fa..52280d5 100644
--- a/lib/random32.c
+++ b/lib/random32.c
@@ -77,6 +77,55 @@ u32 prandom_u32(void)
 }
 EXPORT_SYMBOL(prandom_u32);
 
+/*
+ *	prandom_bytes_state - get the requested number of pseudo-random bytes
+ *
+ *	@state: pointer to state structure holding seeded state.
+ *	@buf: where to copy the pseudo-random bytes to
+ *	@bytes: the requested number of bytes
+ *
+ *	This is used for pseudo-randomness with no outside seeding.
+ *	For more random results, use prandom_bytes().
+ */
+void prandom_bytes_state(struct rnd_state *state, void *buf, int bytes)
+{
+	unsigned char *p = buf;
+	int i;
+
+	for (i = 0; i < round_down(bytes, sizeof(u32)); i += sizeof(u32)) {
+		u32 random = prandom_u32_state(state);
+		int j;
+
+		for (j = 0; j < sizeof(u32); j++) {
+			p[i + j] = random;
+			random >>= BITS_PER_BYTE;
+		}
+	}
+	if (i < bytes) {
+		u32 random = prandom_u32_state(state);
+
+		for (; i < bytes; i++) {
+			p[i] = random;
+			random >>= BITS_PER_BYTE;
+		}
+	}
+}
+EXPORT_SYMBOL(prandom_bytes_state);
+
+/**
+ *	prandom_bytes - get the requested number of pseudo-random bytes
+ *	@buf: where to copy the pseudo-random bytes to
+ *	@bytes: the requested number of bytes
+ */
+void prandom_bytes(void *buf, int bytes)
+{
+	struct rnd_state *state = &get_cpu_var(net_rand_state);
+
+	prandom_bytes_state(state, buf, bytes);
+	put_cpu_var(state);
+}
+EXPORT_SYMBOL(prandom_bytes);
+
 /**
  *	prandom_seed - add entropy to pseudo random number generator
  *	@seed: seed value
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v3 03/11] bnx2x: use prandom_bytes()
  2012-11-13 13:36 [PATCH v3 00/11] rename random32 to prandom and introduce prandom_bytes() Akinobu Mita
  2012-11-13 13:37 ` [PATCH v3 02/11] prandom: introduce prandom_bytes() and prandom_bytes_state() Akinobu Mita
@ 2012-11-13 13:37 ` Akinobu Mita
  2012-11-13 19:55 ` [PATCH v3 00/11] rename random32 to prandom and introduce prandom_bytes() Andrew Morton
  2 siblings, 0 replies; 4+ messages in thread
From: Akinobu Mita @ 2012-11-13 13:37 UTC (permalink / raw)
  To: linux-kernel, akpm; +Cc: Akinobu Mita, Eilon Greenstein, netdev

Use prandom_bytes() to fill rss key with pseudo-random bytes.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Eilon Greenstein <eilong@broadcom.com>
Cc: netdev@vger.kernel.org
---
* v3
- rename random32_get_bytes to prandom_bytes

 drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
index 4833b6a..257d38b 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
@@ -1741,7 +1741,6 @@ int bnx2x_config_rss_pf(struct bnx2x *bp, struct bnx2x_rss_config_obj *rss_obj,
 			bool config_hash)
 {
 	struct bnx2x_config_rss_params params = {NULL};
-	int i;
 
 	/* Although RSS is meaningless when there is a single HW queue we
 	 * still need it enabled in order to have HW Rx hash generated.
@@ -1773,9 +1772,7 @@ int bnx2x_config_rss_pf(struct bnx2x *bp, struct bnx2x_rss_config_obj *rss_obj,
 
 	if (config_hash) {
 		/* RSS keys */
-		for (i = 0; i < sizeof(params.rss_key) / 4; i++)
-			params.rss_key[i] = random32();
-
+		prandom_bytes(params.rss_key, sizeof(params.rss_key));
 		__set_bit(BNX2X_RSS_SET_SRCH, &params.rss_flags);
 	}
 
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v3 00/11] rename random32 to prandom and introduce prandom_bytes()
  2012-11-13 13:36 [PATCH v3 00/11] rename random32 to prandom and introduce prandom_bytes() Akinobu Mita
  2012-11-13 13:37 ` [PATCH v3 02/11] prandom: introduce prandom_bytes() and prandom_bytes_state() Akinobu Mita
  2012-11-13 13:37 ` [PATCH v3 03/11] bnx2x: use prandom_bytes() Akinobu Mita
@ 2012-11-13 19:55 ` Andrew Morton
  2 siblings, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2012-11-13 19:55 UTC (permalink / raw)
  To: Akinobu Mita
  Cc: linux-kernel, Theodore Ts'o, Artem Bityutskiy, Adrian Hunter,
	David Woodhouse, linux-mtd, Eilon Greenstein, netdev, Robert Love,
	devel, Michel Lespinasse

On Tue, 13 Nov 2012 22:36:59 +0900
Akinobu Mita <akinobu.mita@gmail.com> wrote:

> This patchset introduces new functions into random32 library for
> getting the requested number of pseudo-random bytes.
> 
> Before introducing these new functions into random32 library,
> rename all random32 functions to have 'prandom_' prefix.  As a result
> the function prototypes are as follows:
> 
> void prandom_seed(u32 seed);	/* rename from srandom32() */
> u32 prandom_u32(void);		/* rename from random32() */
> void prandom_bytes(void *buf, int nbytes);
> 
> void prandom_seed_state(struct rnd_state *state, u64 seed);
> 				/* rename from prandom32_seed() */
> u32 prandom_u32_state(struct rnd_state *state);
> 				/* rename from prandom32() */
> void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
> 
> The purpose of this renaming is to prevent some kernel developers
> from assuming that prandom32() and random32() might imply that only
> prandom32() was the one using a pseudo-random number generator by
> prandom32's "p", and the result may be a very embarassing security
> exposure.  This concern was expressed by Theodore Ts'o.

There were a large number of rejects in MTD code, due to pending
changes in linux-next.  It's all quite mechanical stuff which I
fixed up.  Please check the result.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-11-13 19:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-13 13:36 [PATCH v3 00/11] rename random32 to prandom and introduce prandom_bytes() Akinobu Mita
2012-11-13 13:37 ` [PATCH v3 02/11] prandom: introduce prandom_bytes() and prandom_bytes_state() Akinobu Mita
2012-11-13 13:37 ` [PATCH v3 03/11] bnx2x: use prandom_bytes() Akinobu Mita
2012-11-13 19:55 ` [PATCH v3 00/11] rename random32 to prandom and introduce prandom_bytes() Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).