From nobody Thu Dec 23 20:19:56 2021 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 605BC18F252C; Thu, 23 Dec 2021 20:19:57 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JKhPn0pXvz4dqW; Thu, 23 Dec 2021 20:19:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id E70EE16A68; Thu, 23 Dec 2021 20:19:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1BNKJu8P031081; Thu, 23 Dec 2021 20:19:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BNKJue3031080; Thu, 23 Dec 2021 20:19:56 GMT (envelope-from git) Date: Thu, 23 Dec 2021 20:19:56 GMT Message-Id: <202112232019.1BNKJue3031080@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Jessica Clarke Subject: git: a34d3ca6efc4 - main - re: Avoid subobject overread when setting IDRn List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jrtc27 X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a34d3ca6efc47eeced62a50a8328a554fa1ad72c Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1640290797; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ufHOL47QNKZ9I2G6Y8EmQrVjifO7BtIKL/krYCmy4AA=; b=JDLhKfbylzVR0xLjBY4C7AF9aVk+POKOuNxdLqEirzUdbrjjZ6exf//FZgpXzCyR9CZMHr 4vwXEW0qWYGk+Atc3j8ppCtrZPkYCLiicyxTJjogp1qJyBjZweWLGK+PzZ5JvhF3tleN09 s8aeljmBErrOpHjOFiqcYCe6S7Sfv3l8W39WjZBHRtXT2INwsSVno4dZATFcgJ140Aok3Y k+wcgbKX5aDRUFrdrGtzJOLsEt8mXWtaR/HPKtQtHdjsR63tPdSuJvRZoAp2TOxn0IfAOx JAEzEClhHkNYilhjJvZspD/yaMrvsjuk5jqh4Mdb1V3jAdkaub3DEwzTugXexg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1640290797; a=rsa-sha256; cv=none; b=QuQn9cqs3s1Om9YIDmTeXY2BWOhROVz1czzg5RlFnwRgPotDTvm0uhLyBbPgVqhlEQlSxX GBxlc4RXxoQp4x5cuF0TWpdHuNfAEis7fqEj01I/dyJyZjhKrVYqbzONYRjKZpup2OnpD2 4rJ0jwZpmkDwVWpzECamb/vzDBmGRoZkMVMaqvEN0vwkobbgKVgvoWrz6qlKlHT4YEepr3 CP9eayGp4KTNW9ROXhkvRKpfzGhSh6gi8W6U0Q7ppJ5kSLl7iCOPlnDwYXmz8Jx6ugDNnF gNWnUqtX+yyLt4RaS9qZCsPDNkOHdO3xvcNNIvoUEBHNsypcj4AdwnCtei+gjQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jrtc27: URL: https://cgit.FreeBSD.org/src/commit/?id=a34d3ca6efc47eeced62a50a8328a554fa1ad72c commit a34d3ca6efc47eeced62a50a8328a554fa1ad72c Author: Jessica Clarke AuthorDate: 2021-12-23 20:19:31 +0000 Commit: Jessica Clarke CommitDate: 2021-12-23 20:19:31 +0000 re: Avoid subobject overread when setting IDRn IDR0-IDR5 can be read byte-by-byte but must be written to as 4-byte words. The current code to do this is rather clunky and ends up reading past the end of the union's eaddr member due to MAC addresses only being 6 bytes. In practice this ends up being fine because the align_dummy member will pad the union to a multiple of 4 bytes, but this is dodgy, and on CHERI with subobject bounds enforcement enabled, as is done in CheriBSD's pure-capability kernel, will trap. Instead, make the buffer in use the right size, just use an array of uint32_t's rather than a char buffer that's then cast to uint32_t * to simplify it in the process, and zero-initialise it first to avoid reading uninitialised data in the trailing bytes. Found by: CHERI Reviewed by: jhb Differential Revision: https://reviews.freebsd.org/D33617 --- sys/dev/re/if_re.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/sys/dev/re/if_re.c b/sys/dev/re/if_re.c index cf327932cd74..5d1446e51abf 100644 --- a/sys/dev/re/if_re.c +++ b/sys/dev/re/if_re.c @@ -3094,10 +3094,7 @@ re_init_locked(struct rl_softc *sc) struct mii_data *mii; uint32_t reg; uint16_t cfg; - union { - uint32_t align_dummy; - u_char eaddr[ETHER_ADDR_LEN]; - } eaddr; + uint32_t idr[2]; RL_LOCK_ASSERT(sc); @@ -3196,12 +3193,11 @@ re_init_locked(struct rl_softc *sc) * register write enable" mode to modify the ID registers. */ /* Copy MAC address on stack to align. */ - bcopy(IF_LLADDR(ifp), eaddr.eaddr, ETHER_ADDR_LEN); + bzero(idr, sizeof(idr)); + bcopy(IF_LLADDR(ifp), idr, ETHER_ADDR_LEN); CSR_WRITE_1(sc, RL_EECMD, RL_EEMODE_WRITECFG); - CSR_WRITE_4(sc, RL_IDR0, - htole32(*(u_int32_t *)(&eaddr.eaddr[0]))); - CSR_WRITE_4(sc, RL_IDR4, - htole32(*(u_int32_t *)(&eaddr.eaddr[4]))); + CSR_WRITE_4(sc, RL_IDR0, htole32(idr[0])); + CSR_WRITE_4(sc, RL_IDR4, htole32(idr[1])); CSR_WRITE_1(sc, RL_EECMD, RL_EEMODE_OFF); /*