Re: [PATCH v32 01/12] Linux Random Number Generator

From: kernel test robot
Date: Thu Aug 20 2020 - 07:49:38 EST


Hi "Stephan,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on char-misc/char-misc-testing]
[also build test WARNING on cryptodev/master crypto/master v5.9-rc1 next-20200820]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url: https://github.com/0day-ci/linux/commits/Stephan-M-ller/dev-random-a-new-approach-with-full-SP800-90B-compliance/20200820-165712
base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git d162219c655c8cf8003128a13840d6c1e183fb80
config: nios2-allyesconfig (attached as .config)
compiler: nios2-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=nios2

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>

All warnings (new ones prefixed by >>):

>> drivers/char/lrng/lrng_interfaces.c:120:6: warning: no previous prototype for 'add_hwgenerator_randomness' [-Wmissing-prototypes]
120 | void add_hwgenerator_randomness(const char *buffer, size_t count,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/char/lrng/lrng_interfaces.c:297:6: warning: no previous prototype for 'get_random_bytes_full' [-Wmissing-prototypes]
297 | void get_random_bytes_full(void *buf, int nbytes)
| ^~~~~~~~~~~~~~~~~~~~~
drivers/char/lrng/lrng_interfaces.c:37:18: warning: array 'random_table' assumed to have one element
37 | struct ctl_table random_table[];
| ^~~~~~~~~~~~

# https://github.com/0day-ci/linux/commit/866aae82856f1fba6af5c4b19a3905800cab4563
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Stephan-M-ller/dev-random-a-new-approach-with-full-SP800-90B-compliance/20200820-165712
git checkout 866aae82856f1fba6af5c4b19a3905800cab4563
vim +/add_hwgenerator_randomness +120 drivers/char/lrng/lrng_interfaces.c

107
108 /**
109 * add_hwgenerator_randomness() - Interface for in-kernel drivers of true
110 * hardware RNGs.
111 *
112 * Those devices may produce endless random bits and will be throttled
113 * when our pool is full.
114 *
115 * @buffer: buffer holding the entropic data from HW noise sources to be used to
116 * insert into entropy pool.
117 * @count: length of buffer
118 * @entropy_bits: amount of entropy in buffer (value is in bits)
119 */
> 120 void add_hwgenerator_randomness(const char *buffer, size_t count,
121 size_t entropy_bits)
122 {
123 /*
124 * Suspend writing if we are fully loaded with entropy.
125 * We'll be woken up again once below lrng_write_wakeup_thresh,
126 * or when the calling thread is about to terminate.
127 */
128 wait_event_interruptible(lrng_write_wait,
129 lrng_need_entropy() ||
130 lrng_state_exseed_allow(lrng_noise_source_hw) ||
131 kthread_should_stop());
132 lrng_state_exseed_set(lrng_noise_source_hw, false);
133 lrng_pool_lfsr_nonaligned(buffer, count);
134 lrng_pool_add_entropy(entropy_bits);
135 }
136 EXPORT_SYMBOL_GPL(add_hwgenerator_randomness);
137
138 /**
139 * add_bootloader_randomness() - Handle random seed passed by bootloader.
140 *
141 * If the seed is trustworthy, it would be regarded as hardware RNGs. Otherwise
142 * it would be regarded as device data.
143 * The decision is controlled by CONFIG_RANDOM_TRUST_BOOTLOADER.
144 *
145 * @buf: buffer holding the entropic data from HW noise sources to be used to
146 * insert into entropy pool.
147 * @size: length of buffer
148 */
149 void add_bootloader_randomness(const void *buf, unsigned int size)
150 {
151 if (IS_ENABLED(CONFIG_RANDOM_TRUST_BOOTLOADER))
152 add_hwgenerator_randomness(buf, size, size * 8);
153 else
154 add_device_randomness(buf, size);
155 }
156 EXPORT_SYMBOL_GPL(add_bootloader_randomness);
157
158 /*
159 * Callback for HID layer -- use the HID event values to stir the entropy pool
160 */
161 void add_input_randomness(unsigned int type, unsigned int code,
162 unsigned int value)
163 {
164 static unsigned char last_value;
165
166 /* ignore autorepeat and the like */
167 if (value == last_value)
168 return;
169
170 last_value = value;
171
172 lrng_pool_lfsr_u32((type << 4) ^ code ^ (code >> 4) ^ value);
173 }
174 EXPORT_SYMBOL_GPL(add_input_randomness);
175
176 /**
177 * add_device_randomness() - Add device- or boot-specific data to the entropy
178 * pool to help initialize it.
179 *
180 * None of this adds any entropy; it is meant to avoid the problem of
181 * the entropy pool having similar initial state across largely
182 * identical devices.
183 *
184 * @buf: buffer holding the entropic data from HW noise sources to be used to
185 * insert into entropy pool.
186 * @size: length of buffer
187 */
188 void add_device_randomness(const void *buf, unsigned int size)
189 {
190 lrng_pool_lfsr_nonaligned((u8 *)buf, size);
191 lrng_pool_lfsr_u32(random_get_entropy());
192 lrng_pool_lfsr_u32(jiffies);
193 }
194 EXPORT_SYMBOL(add_device_randomness);
195
196 #ifdef CONFIG_BLOCK
197 void rand_initialize_disk(struct gendisk *disk) { }
198 void add_disk_randomness(struct gendisk *disk) { }
199 EXPORT_SYMBOL(add_disk_randomness);
200 #endif
201
202 /**
203 * del_random_ready_callback() - Delete a previously registered readiness
204 * callback function.
205 *
206 * @rdy: callback definition that was registered initially
207 */
208 void del_random_ready_callback(struct random_ready_callback *rdy)
209 {
210 unsigned long flags;
211 struct module *owner = NULL;
212
213 spin_lock_irqsave(&lrng_ready_list_lock, flags);
214 if (!list_empty(&rdy->list)) {
215 list_del_init(&rdy->list);
216 owner = rdy->owner;
217 }
218 spin_unlock_irqrestore(&lrng_ready_list_lock, flags);
219
220 module_put(owner);
221 }
222 EXPORT_SYMBOL(del_random_ready_callback);
223
224 /**
225 * add_random_ready_callback() - Add a callback function that will be invoked
226 * when the DRNG is mimimally seeded.
227 *
228 * @rdy: callback definition to be invoked when the LRNG is seeded
229 *
230 * Return:
231 * * 0 if callback is successfully added
232 * * -EALREADY if pool is already initialised (callback not called)
233 * * -ENOENT if module for callback is not alive
234 */
235 int add_random_ready_callback(struct random_ready_callback *rdy)
236 {
237 struct module *owner;
238 unsigned long flags;
239 int err = -EALREADY;
240
241 if (likely(lrng_state_min_seeded()))
242 return err;
243
244 owner = rdy->owner;
245 if (!try_module_get(owner))
246 return -ENOENT;
247
248 spin_lock_irqsave(&lrng_ready_list_lock, flags);
249 if (lrng_state_min_seeded())
250 goto out;
251
252 owner = NULL;
253
254 list_add(&rdy->list, &lrng_ready_list);
255 err = 0;
256
257 out:
258 spin_unlock_irqrestore(&lrng_ready_list_lock, flags);
259
260 module_put(owner);
261
262 return err;
263 }
264 EXPORT_SYMBOL(add_random_ready_callback);
265
266 /*********************** LRNG kernel output interfaces ************************/
267
268 /**
269 * get_random_bytes() - Provider of cryptographic strong random numbers for
270 * kernel-internal usage.
271 *
272 * This function is appropriate for all in-kernel use cases. However,
273 * it will always use the ChaCha20 DRNG.
274 *
275 * @buf: buffer to store the random bytes
276 * @nbytes: size of the buffer
277 */
278 void get_random_bytes(void *buf, int nbytes)
279 {
280 lrng_drng_get_atomic((u8 *)buf, (u32)nbytes);
281 lrng_debug_report_seedlevel("get_random_bytes");
282 }
283 EXPORT_SYMBOL(get_random_bytes);
284
285 /**
286 * get_random_bytes_full() - Provider of cryptographic strong random numbers
287 * for kernel-internal usage.
288 *
289 * This function is appropriate only for non-atomic use cases as this
290 * function may sleep. Though, it provides access to the full functionality
291 * of LRNG including the switchable DRNG support, that may support other
292 * DRNGs such as the SP800-90A DRBG.
293 *
294 * @buf: buffer to store the random bytes
295 * @nbytes: size of the buffer
296 */
> 297 void get_random_bytes_full(void *buf, int nbytes)
298 {
299 lrng_drng_get_sleep((u8 *)buf, (u32)nbytes);
300 lrng_debug_report_seedlevel("get_random_bytes_full");
301 }
302 EXPORT_SYMBOL(get_random_bytes_full);
303

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx

Attachment: .config.gz
Description: application/gzip