From nobody Wed Jul 1 08:52:43 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33D79C433EF for ; Sat, 25 Dec 2021 01:00:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232010AbhLYBAf (ORCPT ); Fri, 24 Dec 2021 20:00:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229549AbhLYBAe (ORCPT ); Fri, 24 Dec 2021 20:00:34 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12BA4C061401 for ; Fri, 24 Dec 2021 17:00:33 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id CC7A7CE2345 for ; Sat, 25 Dec 2021 01:00:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C38D7C36AEA; Sat, 25 Dec 2021 01:00:29 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="IzUQPv+C" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1640394028; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=hq8m6d/730E5cuUPQiSTXZEq/EnTJ9dNV6E7hz3q2hY=; b=IzUQPv+CzKnGZl9VFZ0FOSEmJD8ywH7f3IEsGnl2hemT5H4fveEcXxR3zOuK2JFT2Xv33f AyYolv6x+M1YT9/hJdt+9w2WsZJNlAv8WraxU26bGnnjyNiTVsQcVgUQz9YptXdvAstujv ZA5G/Ml3H3kJUlr9FuC718i4dKfIIxM= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 0b18722d (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Sat, 25 Dec 2021 01:00:27 +0000 (UTC) From: "Jason A. Donenfeld" To: tytso@mit.edu, linux-kernel@vger.kernel.org Cc: "Jason A. Donenfeld" Subject: [PATCH] random: do not sign extend bytes for rotation when mixing Date: Sat, 25 Dec 2021 02:00:11 +0100 Message-Id: <20211225010011.1909938-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" By using `char` instead of `unsigned char`, certain platforms will sign extend the byte when `w =3D rol32(*bytes++, input_rotate)` is called, meaning that bit 7 is overrepresented when mixing. This isn't a real problem (unless the mixer itself is already broken) since it's still invertible, but it's not quite correct either. Fix this by using an explicit unsigned type. Signed-off-by: Jason A. Donenfeld --- drivers/char/random.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/char/random.c b/drivers/char/random.c index 99cce575a79c..82db125aaed7 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -546,7 +546,7 @@ static void _mix_pool_bytes(struct entropy_store *r, co= nst void *in, unsigned long i, tap1, tap2, tap3, tap4, tap5; int input_rotate; int wordmask =3D r->poolinfo->poolwords - 1; - const char *bytes =3D in; + const unsigned char *bytes =3D in; __u32 w; =20 tap1 =3D r->poolinfo->tap1; --=20 2.34.1