From owner-svn-src-head@freebsd.org Tue Sep 3 14:06:18 2019 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 7ACA6DC453; Tue, 3 Sep 2019 14:06:09 +0000 (UTC) (envelope-from yuripv@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2610:1c1:1:6074::16:84]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46N7z45zf4z4PF9; Tue, 3 Sep 2019 14:06:08 +0000 (UTC) (envelope-from yuripv@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 1452) id 65CB21A1D4; Tue, 3 Sep 2019 14:05:59 +0000 (UTC) X-Original-To: yuripv@localmail.freebsd.org Delivered-To: yuripv@localmail.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [96.47.72.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mx1.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by freefall.freebsd.org (Postfix) with ESMTPS id 7788A85D5; Thu, 4 Apr 2019 01:02:55 +0000 (UTC) (envelope-from owner-src-committers@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2610:1c1:1:6074::16:84]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 403C1756F1; Thu, 4 Apr 2019 01:02:55 +0000 (UTC) (envelope-from owner-src-committers@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 538) id 2A5F285D3; Thu, 4 Apr 2019 01:02:55 +0000 (UTC) Delivered-To: src-committers@localmail.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [96.47.72.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mx1.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by freefall.freebsd.org (Postfix) with ESMTPS id 765A285D1 for ; Thu, 4 Apr 2019 01:02:52 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 279E1756EB; Thu, 4 Apr 2019 01:02:52 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 03AD81E0D1; Thu, 4 Apr 2019 01:02:52 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3412pSY013841; Thu, 4 Apr 2019 01:02:51 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3412oHg013833; Thu, 4 Apr 2019 01:02:50 GMT (envelope-from cem@FreeBSD.org) Message-Id: <201904040102.x3412oHg013833@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: Conrad Meyer To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r345865 - in head/sys: cddl/contrib/opensolaris/uts/common/dtrace compat/linuxkpi/common/include/linux net netipsec netpfil/pf X-SVN-Group: head X-SVN-Commit-Author: cem X-SVN-Commit-Paths: in head/sys: cddl/contrib/opensolaris/uts/common/dtrace compat/linuxkpi/common/include/linux net netipsec netpfil/pf X-SVN-Commit-Revision: 345865 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk X-Loop: FreeBSD.org Sender: owner-src-committers@freebsd.org X-Rspamd-Queue-Id: 403C1756F1 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.98 / 15.00]; local_wl_from(0.00)[freebsd.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.98)[-0.983,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] Status: O X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Date: Tue, 03 Sep 2019 14:06:18 -0000 X-Original-Date: Thu, 4 Apr 2019 01:02:50 +0000 (UTC) X-List-Received-Date: Tue, 03 Sep 2019 14:06:18 -0000 Author: cem Date: Thu Apr 4 01:02:50 2019 New Revision: 345865 URL: https://svnweb.freebsd.org/changeset/base/345865 Log: Replace read_random(9) with more appropriate arc4rand(9) KPIs Reviewed by: ae, delphij Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D19760 Modified: head/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c head/sys/compat/linuxkpi/common/include/linux/etherdevice.h head/sys/compat/linuxkpi/common/include/linux/random.h head/sys/net/if_spppsubr.c head/sys/netipsec/key.c head/sys/netipsec/key.h head/sys/netipsec/xform_esp.c head/sys/netpfil/pf/pf.c Modified: head/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c ============================================================================== --- head/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c Thu Apr 4 00:05:36 2019 (r345864) +++ head/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c Thu Apr 4 01:02:50 2019 (r345865) @@ -14631,7 +14631,7 @@ dtrace_state_create(struct cdev *dev, struct ucred *cr * SI_SUB_RANDOM < SI_SUB_DTRACE_ANON therefore entropy device is * assumed to be seeded at this point (if from Fortuna seed file). */ - (void) read_random(&state->dts_rstate[0], 2 * sizeof(uint64_t)); + arc4random_buf(&state->dts_rstate[0], 2 * sizeof(uint64_t)); for (cpu_it = 1; cpu_it < NCPU; cpu_it++) { /* * Each CPU is assigned a 2^64 period, non-overlapping Modified: head/sys/compat/linuxkpi/common/include/linux/etherdevice.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/linux/etherdevice.h Thu Apr 4 00:05:36 2019 (r345864) +++ head/sys/compat/linuxkpi/common/include/linux/etherdevice.h Thu Apr 4 01:02:50 2019 (r345865) @@ -108,8 +108,7 @@ eth_zero_addr(u8 *pa) static inline void random_ether_addr(u8 * dst) { - if (read_random(dst, 6) == 0) - arc4rand(dst, 6, 0); + arc4random_buf(dst, 6); dst[0] &= 0xfe; dst[0] |= 0x02; Modified: head/sys/compat/linuxkpi/common/include/linux/random.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/linux/random.h Thu Apr 4 00:05:36 2019 (r345864) +++ head/sys/compat/linuxkpi/common/include/linux/random.h Thu Apr 4 01:02:50 2019 (r345865) @@ -39,8 +39,7 @@ static inline void get_random_bytes(void *buf, int nbytes) { - if (read_random(buf, nbytes) == 0) - arc4rand(buf, nbytes, 0); + arc4random_buf(buf, nbytes); } static inline u_int Modified: head/sys/net/if_spppsubr.c ============================================================================== --- head/sys/net/if_spppsubr.c Thu Apr 4 00:05:36 2019 (r345864) +++ head/sys/net/if_spppsubr.c Thu Apr 4 01:02:50 2019 (r345865) @@ -4337,16 +4337,12 @@ sppp_chap_tld(struct sppp *sp) static void sppp_chap_scr(struct sppp *sp) { - u_long *ch, seed; + u_long *ch; u_char clen; /* Compute random challenge. */ ch = (u_long *)sp->myauth.challenge; - read_random(&seed, sizeof seed); - ch[0] = seed ^ random(); - ch[1] = seed ^ random(); - ch[2] = seed ^ random(); - ch[3] = seed ^ random(); + arc4random_buf(ch, 4 * sizeof(*ch)); clen = AUTHKEYLEN; sp->confid[IDX_CHAP] = ++sp->pp_seq[IDX_CHAP]; Modified: head/sys/netipsec/key.c ============================================================================== --- head/sys/netipsec/key.c Thu Apr 4 00:05:36 2019 (r345864) +++ head/sys/netipsec/key.c Thu Apr 4 01:02:50 2019 (r345865) @@ -4760,32 +4760,8 @@ key_random() { u_long value; - key_randomfill(&value, sizeof(value)); + arc4random_buf(&value, sizeof(value)); return value; -} - -void -key_randomfill(void *p, size_t l) -{ - size_t n; - u_long v; - static int warn = 1; - - n = 0; - n = (size_t)read_random(p, (u_int)l); - /* last resort */ - while (n < l) { - v = random(); - bcopy(&v, (u_int8_t *)p + n, - l - n < sizeof(v) ? l - n : sizeof(v)); - n += sizeof(v); - - if (warn) { - printf("WARNING: pseudo-random number generator " - "used for IPsec processing\n"); - warn = 0; - } - } } /* Modified: head/sys/netipsec/key.h ============================================================================== --- head/sys/netipsec/key.h Thu Apr 4 00:05:36 2019 (r345864) +++ head/sys/netipsec/key.h Thu Apr 4 01:02:50 2019 (r345865) @@ -78,7 +78,6 @@ void key_unregister_ifnet(struct secpolicy **, u_int); void key_delete_xform(const struct xformsw *); extern u_long key_random(void); -extern void key_randomfill(void *, size_t); extern void key_freereg(struct socket *); extern int key_parse(struct mbuf *, struct socket *); extern void key_init(void); Modified: head/sys/netipsec/xform_esp.c ============================================================================== --- head/sys/netipsec/xform_esp.c Thu Apr 4 00:05:36 2019 (r345864) +++ head/sys/netipsec/xform_esp.c Thu Apr 4 01:02:50 2019 (r345865) @@ -768,7 +768,7 @@ esp_output(struct mbuf *m, struct secpolicy *sp, struc */ switch (sav->flags & SADB_X_EXT_PMASK) { case SADB_X_EXT_PRAND: - (void) read_random(pad, padding - 2); + arc4random_buf(pad, padding - 2); break; case SADB_X_EXT_PZERO: bzero(pad, padding - 2); Modified: head/sys/netpfil/pf/pf.c ============================================================================== --- head/sys/netpfil/pf/pf.c Thu Apr 4 00:05:36 2019 (r345864) +++ head/sys/netpfil/pf/pf.c Thu Apr 4 01:02:50 2019 (r345865) @@ -3207,7 +3207,7 @@ pf_tcp_iss(struct pf_pdesc *pd) u_int32_t digest[4]; if (V_pf_tcp_secret_init == 0) { - read_random(&V_pf_tcp_secret, sizeof(V_pf_tcp_secret)); + arc4random_buf(&V_pf_tcp_secret, sizeof(V_pf_tcp_secret)); MD5Init(&V_pf_tcp_secret_ctx); MD5Update(&V_pf_tcp_secret_ctx, V_pf_tcp_secret, sizeof(V_pf_tcp_secret));