From patchwork Wed Oct 19 16:26:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 5746 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp429143wrs; Wed, 19 Oct 2022 09:51:17 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4GqiAB9SnbMEt5Q7kNKaENcTPvnyCYnv5xQC+L0M5UjI1rCcFlk8QuSBNP24yrtd/PDhZx X-Received: by 2002:a17:907:8a0a:b0:78d:b87d:e68a with SMTP id sc10-20020a1709078a0a00b0078db87de68amr7303022ejc.301.1666198277009; Wed, 19 Oct 2022 09:51:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666198277; cv=none; d=google.com; s=arc-20160816; b=oArY2MfN0Xu+VZCGNt8ANWaxpT2Na13ii1EkE/c13mNier4XtzE+qQsXv4uM2L/ugg Lc1BxqBqIhMyLX6QkYYPcofv2soq7Iml7iDo95wFaSz2sDpsgf/fEfIsRyYEImuQHPBc FlkHKSXvjM2UfGyUZ3Vdvf8Uf6hePfiIwqJrWDMP9j7y8q/D4odlTq+enPLy7ghu2D76 3wfh6CZ0AkbDgFxIH4d1KW9xxmQ806fgRDDCuC1qvBUMSaRc1pXKfm+DYCYz2VvO1jrQ kLsiLXTkwkKU18vBjCS0UfwDczl7oui9Uwv+vgWSk8tiAGZ5e/4tnNt9z+5RFyupFzq1 5MaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=0lT+uEqlVaVxzDYYTi6dahuFCqqiYtCEv6lPMBO9aIk=; b=F66OImcbE5RBs6VC60o+FrEyT88O/JWl5zrkeX5/rqZvS3qJ8BtGapifZo5IZLhZCJ 1LIQtV3hL0HJ3H/iNSzmPYfnjL1t6oBAoN0b7rhBq7vmOVKzt6ec1yiSt3vKVg6VEfyX YRTWtjnZimkSSQ8XqKeAhP8vLB0WrI6hSLGVCuiUSpo1nEUhflvp4ipIYYmx5lR/XqSY xcN4Ik1HC9RcIsmUhcxCZc9DsMtKVT112g0uiuQx/v2VMO1UrUwOuojABQ7hr5J9LTi8 hcIWrYySVEfpsXjJod7J6LLLkRc6/pBNREx900Zyu7GaeFvq7VtUAyEA5CbzuWEUAL/L 8w0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=US7FiyUD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=zx2c4.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m15-20020a1709066d0f00b007881b45441asi12606667ejr.721.2022.10.19.09.50.50; Wed, 19 Oct 2022 09:51:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=US7FiyUD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230075AbiJSQ1f (ORCPT + 99 others); Wed, 19 Oct 2022 12:27:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230180AbiJSQ1c (ORCPT ); Wed, 19 Oct 2022 12:27:32 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C945E43627; Wed, 19 Oct 2022 09:27:31 -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 82681B8250F; Wed, 19 Oct 2022 16:27:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3CFB4C433D7; Wed, 19 Oct 2022 16:27:28 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="US7FiyUD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1666196844; 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=0lT+uEqlVaVxzDYYTi6dahuFCqqiYtCEv6lPMBO9aIk=; b=US7FiyUDe8pnYz6rD3uwg9fXnSMZscFIYdtfIpv4nXWoaXgeagZoP4Aq3+1ycyM4jN6PAA sT+vCEuPGTqjOb5tSTOdYoqhRAvMz/77p4eWWarEYDA2lmcA6GsdYvOM4SHdT534zEmMVR WZGPFOwIokjYZRMKO5MEMdMo3HOL2z4= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id f51d3b10 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 19 Oct 2022 16:27:24 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-arch@vger.kernel.org, linux-toolchains@vger.kernel.org Cc: "Jason A. Donenfeld" , Masahiro Yamada , Kees Cook , Andrew Morton , Linus Torvalds , Andy Shevchenko , Greg Kroah-Hartman Subject: [PATCH] kbuild: treat char as always signed Date: Wed, 19 Oct 2022 10:26:48 -0600 Message-Id: <20221019162648.3557490-1-Jason@zx2c4.com> MIME-Version: 1.0 X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747135524529044627?= X-GMAIL-MSGID: =?utf-8?q?1747135524529044627?= Recently, some compile-time checking I added to the clamp_t family of functions triggered a build error when a poorly written driver was compiled on ARM, because the driver assumed that the naked `char` type is signed, but ARM treats it as unsigned, and the C standard says it's architecture-dependent. I doubt this particular driver is the only instance in which unsuspecting authors assume that `char` with no `signed` or `unsigned` designation is signed, because that's how the other types work. We were lucky enough this time that that driver used `clamp_t(char, negative_value, positive_value)`, so the new checking code found it, and I've sent a patch to fix it, but there are likely other places lurking that won't be so easily unearthed. So let's just eliminate this particular variety of heisensigned bugs entirely. Set `-fsigned-char` globally, so that gcc makes the type signed on all architectures. Cc: Masahiro Yamada Cc: Kees Cook Cc: Andrew Morton Cc: Linus Torvalds Cc: Andy Shevchenko Cc: Greg Kroah-Hartman Link: https://lore.kernel.org/lkml/202210190108.ESC3pc3D-lkp@intel.com/ Signed-off-by: Jason A. Donenfeld --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f41ec8c8426b..f1abcaf7110e 100644 --- a/Makefile +++ b/Makefile @@ -562,7 +562,7 @@ KBUILD_AFLAGS := -D__ASSEMBLY__ -fno-PIE KBUILD_CFLAGS := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \ -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \ -Werror=implicit-function-declaration -Werror=implicit-int \ - -Werror=return-type -Wno-format-security \ + -Werror=return-type -Wno-format-security -fsigned-char \ -std=gnu11 KBUILD_CPPFLAGS := -D__KERNEL__ KBUILD_RUSTFLAGS := $(rust_common_flags) \