From mboxrd@z Thu Jan 1 00:00:00 1970 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 us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [170.10.133.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4B8B1C433F5 for ; Thu, 5 May 2022 07:13:20 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-52-zk2XPSN4MD-rG-B9g6mMrA-1; Thu, 05 May 2022 03:13:17 -0400 X-MC-Unique: zk2XPSN4MD-rG-B9g6mMrA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E5B1D80418F; Thu, 5 May 2022 07:13:14 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id D3FA840D2973; Thu, 5 May 2022 07:13:14 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C24DB1947078; Thu, 5 May 2022 07:13:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D41BC1947043 for ; Wed, 4 May 2022 09:48:12 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id B2AB6C27EB1; Wed, 4 May 2022 09:48:12 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast07.extmail.prod.ext.rdu2.redhat.com [10.11.55.23]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AF232C27EB0 for ; Wed, 4 May 2022 09:48:12 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 639663C11A05 for ; Wed, 4 May 2022 09:48:12 +0000 (UTC) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-475-WcHEo_N_MxyP39QbHvW7RA-1; Wed, 04 May 2022 05:48:09 -0400 X-MC-Unique: WcHEo_N_MxyP39QbHvW7RA-1 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 dfw.source.kernel.org (Postfix) with ESMTPS id 78C6861A0F; Wed, 4 May 2022 09:42:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DECB8C385A4; Wed, 4 May 2022 09:42:34 +0000 (UTC) Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 63f3361b (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Wed, 4 May 2022 09:42:32 +0000 (UTC) Date: Wed, 4 May 2022 11:42:27 +0200 From: "Jason A. Donenfeld" To: Stafford Horne Message-ID: References: MIME-Version: 1.0 In-Reply-To: X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-Mailman-Approved-At: Thu, 05 May 2022 07:13:10 +0000 Subject: Re: [dm-devel] [PATCH v2] hex2bin: make the function hex_to_bin constant-time X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andy Shevchenko , Mike Snitzer , Herbert Xu , Linux Kernel Mailing List , Mimi Zohar , Milan Broz , device-mapper development , Mikulas Patocka , Linux Crypto Mailing List , Linus Torvalds , "David S. Miller" Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dm-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit On Wed, May 04, 2022 at 05:38:28PM +0900, Stafford Horne wrote: > Just a heads up it seems this patch is causing some instability with crypto self > tests on OpenRISC when using a PREEMPT kernel (no SMP). > > This was reported by Jason A. Donenfeld as it came up in wireguard testing. > > I am trying to figure out if this is an OpenRISC PREEMPT issue or something > else. The code of this commit looks fine. And actually the bug goes away if you just add a `pr_err("hello!\n");` to the function. Plus, the function is never called by that test kernel. Actually, the bug even goes away if you change the sign of the input back to naked char (which might be semantically better anyway) and then let the function itself do the sign change (see below). So more likely is that this patch just helps unmask a real issue elsewhere -- linker, compiler, or register restoration after preemption. I don't think there's anything to do with regards to the patch of this thread, as it's clearly fine. Unless you want that sign thing below, but even then, who cares. We should keep digging in on the OpenRISC front. Jason diff --git a/include/linux/kernel.h b/include/linux/kernel.h index fe6efb24d151..a890428bcc1a 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -285,7 +285,7 @@ static inline char *hex_byte_pack_upper(char *buf, u8 byte) return buf; } -extern int hex_to_bin(unsigned char ch); +extern int hex_to_bin(char ch); extern int __must_check hex2bin(u8 *dst, const char *src, size_t count); extern char *bin2hex(char *dst, const void *src, size_t count); diff --git a/lib/hexdump.c b/lib/hexdump.c index 06833d404398..b636b4dcabe9 100644 --- a/lib/hexdump.c +++ b/lib/hexdump.c @@ -43,9 +43,9 @@ EXPORT_SYMBOL(hex_asc_upper); * uppercase and lowercase letters, so we use (ch & 0xdf), which converts * lowercase to uppercase */ -int hex_to_bin(unsigned char ch) +int hex_to_bin(char ch) { - unsigned char cu = ch & 0xdf; + unsigned char cu = ch & 0xdfU; return -1 + ((ch - '0' + 1) & (unsigned)((ch - '9' - 1) & ('0' - 1 - ch)) >> 8) + ((cu - 'A' + 11) & (unsigned)((cu - 'F' - 1) & ('A' - 1 - cu)) >> 8); -- dm-devel mailing list dm-devel@redhat.com https://listman.redhat.com/mailman/listinfo/dm-devel From mboxrd@z Thu Jan 1 00:00:00 1970 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 33C39C433EF for ; Wed, 4 May 2022 09:42:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347664AbiEDJqP (ORCPT ); Wed, 4 May 2022 05:46:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238227AbiEDJqO (ORCPT ); Wed, 4 May 2022 05:46:14 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 178AF275F4; Wed, 4 May 2022 02:42:38 -0700 (PDT) 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 ams.source.kernel.org (Postfix) with ESMTPS id 89262B8247D; Wed, 4 May 2022 09:42:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DECB8C385A4; Wed, 4 May 2022 09:42:34 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="pnyjJaBx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1651657353; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=rW8jljRy3Yv58kuAXOgiGvBjEiUQtfJh49L05E5LnJg=; b=pnyjJaBxYB8uxpm85cAzg+UNyvNUKlJY68olIPhtFJxzIB6Az8cAmeZn05XBKXoj6KdN3D dJ0ZMZKvhABjnKudXmfoGJffPOJgxEyK/Pgc5HavqgBr96VCCH6zl/ibmtnbfSJJ66KYUv R0f/AYldMZwS+QxwVl7hgN9DknE4VmE= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 63f3361b (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Wed, 4 May 2022 09:42:32 +0000 (UTC) Date: Wed, 4 May 2022 11:42:27 +0200 From: "Jason A. Donenfeld" To: Stafford Horne Cc: Mikulas Patocka , Linus Torvalds , Andy Shevchenko , device-mapper development , Linux Kernel Mailing List , Linux Crypto Mailing List , Herbert Xu , "David S. Miller" , Mike Snitzer , Mimi Zohar , Milan Broz Subject: Re: [PATCH v2] hex2bin: make the function hex_to_bin constant-time Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Wed, May 04, 2022 at 05:38:28PM +0900, Stafford Horne wrote: > Just a heads up it seems this patch is causing some instability with crypto self > tests on OpenRISC when using a PREEMPT kernel (no SMP). > > This was reported by Jason A. Donenfeld as it came up in wireguard testing. > > I am trying to figure out if this is an OpenRISC PREEMPT issue or something > else. The code of this commit looks fine. And actually the bug goes away if you just add a `pr_err("hello!\n");` to the function. Plus, the function is never called by that test kernel. Actually, the bug even goes away if you change the sign of the input back to naked char (which might be semantically better anyway) and then let the function itself do the sign change (see below). So more likely is that this patch just helps unmask a real issue elsewhere -- linker, compiler, or register restoration after preemption. I don't think there's anything to do with regards to the patch of this thread, as it's clearly fine. Unless you want that sign thing below, but even then, who cares. We should keep digging in on the OpenRISC front. Jason diff --git a/include/linux/kernel.h b/include/linux/kernel.h index fe6efb24d151..a890428bcc1a 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -285,7 +285,7 @@ static inline char *hex_byte_pack_upper(char *buf, u8 byte) return buf; } -extern int hex_to_bin(unsigned char ch); +extern int hex_to_bin(char ch); extern int __must_check hex2bin(u8 *dst, const char *src, size_t count); extern char *bin2hex(char *dst, const void *src, size_t count); diff --git a/lib/hexdump.c b/lib/hexdump.c index 06833d404398..b636b4dcabe9 100644 --- a/lib/hexdump.c +++ b/lib/hexdump.c @@ -43,9 +43,9 @@ EXPORT_SYMBOL(hex_asc_upper); * uppercase and lowercase letters, so we use (ch & 0xdf), which converts * lowercase to uppercase */ -int hex_to_bin(unsigned char ch) +int hex_to_bin(char ch) { - unsigned char cu = ch & 0xdf; + unsigned char cu = ch & 0xdfU; return -1 + ((ch - '0' + 1) & (unsigned)((ch - '9' - 1) & ('0' - 1 - ch)) >> 8) + ((cu - 'A' + 11) & (unsigned)((cu - 'F' - 1) & ('A' - 1 - cu)) >> 8);