blob: 8aa13bf8b8122a3184428797a4fdc058db54e683 [file] [log] [blame]
Brad Bishop316dfdd2018-06-25 12:45:53 -04001rng-tools: modify 'read error' message
2
3Make the 'read error' message more descriptive.
4
5Copied from https://bugzilla.redhat.com/attachment.cgi?id=1295857
6and modified in one place to apply successfully. Error message during
7bootstrap modified to show device name.
8
9Upstream-Status: pending
10
11Signed-off-by: Joe Slater <joe.slater@windriver.com>
12
13
14--- a/rngd.c
15+++ b/rngd.c
16@@ -247,8 +247,11 @@ static void do_loop(int random_step)
17 continue; /* failed, no work */
18
19 retval = iter->xread(buf, sizeof buf, iter);
20- if (retval)
21+ if (retval) {
22+ message(LOG_DAEMON|LOG_ERR,
23+ "Error reading from entropy source\n");
24 continue; /* failed, no work */
25+ }
26
27 work_done = true;
28
29--- a/rngd_entsource.c
30+++ b/rngd_entsource.c
31@@ -63,10 +63,8 @@ int xread(void *buf, size_t size, struct
32 size -= r;
33 }
34
35- if (size) {
36- message(LOG_DAEMON|LOG_ERR, "read error\n");
37+ if (size)
38 return -1;
39- }
40 return 0;
41 }
42
43@@ -152,7 +150,7 @@ error_out:
44 }
45
46 /* Initialize entropy source */
47-static int discard_initial_data(struct rng *ent_src)
48+static int discard_initial_data(struct rng *ent_src, int *buf)
49 {
50 /* Trash 32 bits of what is probably stale (non-random)
51 * initial state from the RNG. For Intel's, 8 bits would
52@@ -164,10 +162,12 @@ static int discard_initial_data(struct r
53 xread(tempbuf, sizeof(tempbuf), ent_src);
54
55 /* Return 32 bits of bootstrap data */
56- xread(tempbuf, sizeof(tempbuf), ent_src);
57+ if (xread(tempbuf, sizeof(tempbuf), ent_src) != 0)
58+ return -1;
59
60- return tempbuf[0] | (tempbuf[1] << 8) |
61+ *buf = tempbuf[0] | (tempbuf[1] << 8) |
62 (tempbuf[2] << 16) | (tempbuf[3] << 24);
63+ return 0;
64 }
65
66 /*
67@@ -175,6 +175,8 @@ static int discard_initial_data(struct r
68 */
69 int init_entropy_source(struct rng *ent_src)
70 {
71+ int bootstrap;
72+
73 ent_src->rng_fd = open(ent_src->rng_name, O_RDONLY);
74 if (ent_src->rng_fd == -1) {
75 return 1;
76@@ -182,7 +184,11 @@ int init_entropy_source(struct rng *ent_
77 src_list_add(ent_src);
78 /* Bootstrap FIPS tests */
79 ent_src->fipsctx = malloc(sizeof(fips_ctx_t));
80- fips_init(ent_src->fipsctx, discard_initial_data(ent_src));
81+ if (discard_initial_data(ent_src, &bootstrap) != 0) {
82+ message(LOG_ERR|LOG_INFO, "Read failure in %s during bootstrap\n",ent_src->rng_name);
83+ return 1;
84+ }
85+ fips_init(ent_src->fipsctx, bootstrap);
86 return 0;
87 }
88
89--- a/rngtest.c
90+++ b/rngtest.c
91@@ -335,6 +335,7 @@ static int discard_initial_data(void)
92
93 return tempbuf[0] | (tempbuf[1] << 8) |
94 (tempbuf[2] << 16) | (tempbuf[3] << 24);
95+
96 }
97
98 static void do_rng_fips_test_loop( void )