From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/6904 Path: news.gmane.org!not-for-mail From: =?UTF-8?Q?Daniel_Cegie=C5=82ka?= Newsgroups: gmane.linux.lib.musl.general Subject: Re: getrandom syscall Date: Wed, 28 Jan 2015 18:02:24 +0100 Message-ID: References: <20150128145410.GH4574@brightrain.aerifal.cx> <20150128154108.GH32318@port70.net> <20150128160352.GI32318@port70.net> <20150128162104.GJ4574@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=047d7b33d974142e1d050db95766 X-Trace: ger.gmane.org 1422464581 13100 80.91.229.3 (28 Jan 2015 17:03:01 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 28 Jan 2015 17:03:01 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-6917-gllmg-musl=m.gmane.org@lists.openwall.com Wed Jan 28 18:03:01 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1YGW15-00088P-9C for gllmg-musl@m.gmane.org; Wed, 28 Jan 2015 18:02:59 +0100 Original-Received: (qmail 3310 invoked by uid 550); 28 Jan 2015 17:02:57 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 3299 invoked from network); 28 Jan 2015 17:02:56 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=bIVxv/Zfp96n/v/XNhCXWG7FStR3h7lRshYAAJGQTQc=; b=BWDleTlLjEvR/poT3jOfjeLuTTfoSOEYd5XNDegYiletpgiE83RfQsy05oldwt2Zdb 1kXLkIgyS4E+Qv87qLfFW+WIMP6jYd7ljg/I9X0nUC2au8Oo6alwmDDc3i6zI9NTrdvB foTR6vT2c42pcMNS1QgqqLg6lJNgA19ylNvDcehbBKNsYmzkWS9zZEI0X3SwOtVojFhq i/qiPoYDhgH+jM2YZZZZeN1p3gXYCUYYczvwBHUHbw9KFdSyCglWxrBpkLyMRi1YHPNO oPnopCg/q20So4+FYmprdcZgwu/g0bndzKtOo46i2AUEAG7fFxTfexNPKRC/gRnTYuGY DDFA== X-Received: by 10.60.92.5 with SMTP id ci5mr2791879oeb.26.1422464564578; Wed, 28 Jan 2015 09:02:44 -0800 (PST) In-Reply-To: <20150128162104.GJ4574@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:6904 Archived-At: --047d7b33d974142e1d050db95766 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 2015-01-28 17:21 GMT+01:00 Rich Felker : > On Wed, Jan 28, 2015 at 05:12:31PM +0100, Daniel Cegie=C5=82ka wrote: >> >> int getentropy(void *buf, size_t buflen) >> { >> int ret; >> >> if (buflen > 256) >> goto failure; >> ret =3D getrandom(buf, buflen, 0); >> if (ret < 0) >> return ret; >> if (ret =3D=3D buflen) >> return 0; >> failure: >> errno =3D EIO; >> return -1; >> } > > Is it intentional to fall through to failure when ret is positive but > less than buflen? Can this happen? This is a Theodore Tso version... > >> #include "syscall.h" >> >> int getrandom(void *buf, size_t buflen, unsigned int flags) >> { >> return syscall(SYS_getrandom, buf, buflen, flags); >> } > > If I read the documentation correctly, the removed EINTR handling is > irrelevant since the kernel guarantees not to EINTR for <=3D256 bytes > with the default flags, right? yes, and if it is above 256, it can be blocked and there is no guarantee. > Rich --047d7b33d974142e1d050db95766 Content-Type: text/x-csrc; charset=US-ASCII; name="getentropy.c" Content-Disposition: attachment; filename="getentropy.c" Content-Transfer-Encoding: base64 X-Attachment-Id: f_i5gxtvl80 aW50IGdldGVudHJvcHkodm9pZCAqYnVmLCBzaXplX3QgbGVuKQp7CglpbnQgcmV0LCBwcmVfZXJy bm8gPSBlcnJubzsKCglpZiAobGVuID4gMjU2KSB7CgkJZXJybm8gPSBFSU87CgkJcmV0dXJuIC0x OwoJfQoJd2hpbGUgKChyZXQgPSBfX3N5c2NhbGwoU1lTX2dldHJhbmRvbSwgYnVmLCBsZW4sIDAp KSA9PSAtRUlOVFIpOwoJaWYgKHJldCAhPSBsZW4pCgkJcmV0dXJuIC0xOwoJZXJybm8gPSBwcmVf ZXJybm87CglyZXR1cm4gMDsKfQo= --047d7b33d974142e1d050db95766--