Skip to content

Commit 12b7f5f

Browse files
committed
Merge: crypto: rng - Fix extrng EFAULT handling
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/6000 JIRA: https://issues.redhat.com/browse/RHEL-68420 Upstream Status: RHEL only When the iov_iter change was added the EFAULT handling became broken. Fix it by checking that copy_to_iter copied the correct number of bytes. Also make sure that a failure in crypto_rng_get_bytes does not cause previous bytes to be discarded. Finally update the scheduling code per get_random_bytes_user. Signed-off-by: Herbert Xu <herbert.xu@redhat.com> Approved-by: Vladis Dronov <vdronov@redhat.com> Approved-by: Phil Auld <pauld@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Rado Vrbovsky <rvrbovsk@redhat.com>
2 parents ce88cae + 4783569 commit 12b7f5f

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

crypto/rng.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,20 +295,21 @@ static ssize_t crypto_devrandom_read_iter(struct iov_iter *iter, bool reseed)
295295
i = min_t(size_t, iov_iter_count(iter), sizeof(tmp));
296296
err = crypto_rng_get_bytes(rng, tmp, i);
297297
if (err) {
298-
ret = err;
298+
ret = ret ?: err;
299299
break;
300300
}
301301

302302
copied = copy_to_iter(tmp, i, iter);
303303
ret += copied;
304304

305-
if (!iov_iter_count(iter) || copied != sizeof(tmp))
305+
if (!iov_iter_count(iter) || copied != i)
306306
break;
307307

308-
if (need_resched()) {
308+
BUILD_BUG_ON(PAGE_SIZE % sizeof(tmp) != 0);
309+
if (ret % PAGE_SIZE == 0) {
309310
if (signal_pending(current))
310311
break;
311-
schedule();
312+
cond_resched();
312313
}
313314
}
314315

@@ -317,8 +318,7 @@ static ssize_t crypto_devrandom_read_iter(struct iov_iter *iter, bool reseed)
317318
else
318319
crypto_put_default_rng();
319320
memzero_explicit(tmp, sizeof(tmp));
320-
321-
return ret;
321+
return ret ? ret : -EFAULT;
322322
}
323323

324324
static const struct random_extrng crypto_devrandom_rng = {

0 commit comments

Comments
 (0)