From: Jan Stancek <jstancek@redhat.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] syscalls/getrandom02: lower bufsize if low on entropy
Date: Wed, 5 Feb 2020 09:32:11 -0500 (EST) [thread overview]
Message-ID: <1751041821.5968536.1580913131753.JavaMail.zimbra@redhat.com> (raw)
In-Reply-To: <CAEemH2fnu9nZiGDfa5LTTMA0a_-PJ35fjjLdZ2vXYNGRJqHfVA@mail.gmail.com>
----- Original Message -----
> >
> > @@ -37,11 +39,17 @@ static int check_content(unsigned char *buf, int nb)
> > static void verify_getrandom(unsigned int n)
> > {
> > unsigned char buf[256];
> > + int bufsize = 64, entropy_avail;
> >
>
> I'm not sure why here initialize bufsize as 64? can you explain more?
That would be the default, unless we know we have enough entropy.
I picked 64 as it matches 'random_read_wakeup_bits'. Assuming we can get
1bit/s entropy, then potentially worst case of waiting 4x for 64bit,
it should still fit within default 300 seconds.
But it's also rule of thumb, because it's smaller.
>
>
> >
> > - memset(buf, 0, sizeof(buf));
> > + if (access(PROC_ENTROPY_AVAIL, F_OK) == 0) {
> > + SAFE_FILE_SCANF(PROC_ENTROPY_AVAIL, "%d", &entropy_avail);
> > + if (entropy_avail > 256)
> > + bufsize = sizeof(buf);
> > + }
> >
> > + memset(buf, 0, sizeof(buf));
> > do {
> > - TEST(tst_syscall(__NR_getrandom, buf, sizeof(buf),
> > modes[n]));
> > + TEST(tst_syscall(__NR_getrandom, buf, bufsize, modes[n]));
> > } while ((modes[n] & GRND_NONBLOCK) && TST_RET == -1
> > && TST_ERR == EAGAIN);
> >
> > --
> > 2.18.1
> >
> >
> > --
> > Mailing list info: https://lists.linux.it/listinfo/ltp
> >
> >
>
> --
> Regards,
> Li Wang
>
next prev parent reply other threads:[~2020-02-05 14:32 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-05 9:19 [LTP] [PATCH] syscalls/getrandom02: lower bufsize if low on entropy Jan Stancek
2020-02-05 13:57 ` Li Wang
2020-02-05 14:20 ` Li Wang
2020-02-05 14:32 ` Jan Stancek [this message]
2020-02-06 7:01 ` Li Wang
2020-02-07 11:19 ` Cyril Hrubis
2020-02-07 11:26 ` Jan Stancek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1751041821.5968536.1580913131753.JavaMail.zimbra@redhat.com \
--to=jstancek@redhat.com \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox