From patchwork Wed Oct 19 20:30:34 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: 5834 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp527122wrs; Wed, 19 Oct 2022 13:46:51 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6gXmMWSiDwkDaDun6/wGZZZV0zuseQcyxhkbz6vETep9j49pkTfn+++gEa/vU7HevGoy// X-Received: by 2002:a63:90c1:0:b0:45f:c9a7:15c3 with SMTP id a184-20020a6390c1000000b0045fc9a715c3mr8699225pge.304.1666212411386; Wed, 19 Oct 2022 13:46:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666212411; cv=none; d=google.com; s=arc-20160816; b=B1RRGXkUxuMv3/e4xxV4u8DJ8m4eyse0EFvxSkmMtNwGcv7PfqkvKRIWrwUNJa2lvF puQVtsxQVTKSdC1Vk/AW8/DaHQitlErSP/ADk2GdjLtps4v2KBKstCBGd5fJcG9qleYX OsfhKVud2EtraMgT/c2h/USYHHnV0DTXOmpdIRf9Ho0EIf76qf2hM5xUNuz8NaffqxwY wOIlXjAHODL5PtdB6F1l8drf3jtrQGoTBk+Cx0FfIkjRFBOEkBIY+/WXsx9rBbKAwiV0 hgcWkaqvym7MTV2gZmHPUiIvq+wIbtGvmGzfWSVIgeoSi9Ln4b52m4ffIv03I+e7gOjW dUOg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=D096jznuqlRQwJxMQwcMaa14sQx4bVWfoMm54xn0QwQ=; b=ZbrkA9zu8yqjhdFGmBbCSgLG9E2JzByjLFVCXM/YfKsyVbQFRGulBzFG4+ivdMQpu3 h/83rLIRDiTT+31HOJtXTwgkWGEwbf9gq+aWn+VjHhGtaWVE8IfStDDVuIdY1Q3/gCgH EIW3KTGvDb6CNesE0INyVGxCLwzkksvlQyv3VaUlBmLWnhroEcuFM1BPdAiEnPIzEnD+ X2FUDfoYcl+Em+Wr5wZi0kYKXlL1ijVAz250kilII0b2xycQUusAb05tytNzHxcv+vGr z88QeACrbRDaxZZMiiKALftMGGa3ycBPH52sbMN2n4lZaWLCCfh7Xos8pE47DWTtxtUr 3peg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=m3pCQfIb; 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 np10-20020a17090b4c4a00b001fd6e58cd98si1003264pjb.123.2022.10.19.13.46.39; Wed, 19 Oct 2022 13:46:51 -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=m3pCQfIb; 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 S229697AbiJSUbE (ORCPT + 99 others); Wed, 19 Oct 2022 16:31:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231394AbiJSUa4 (ORCPT ); Wed, 19 Oct 2022 16:30:56 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31FFD16E292; Wed, 19 Oct 2022 13:30:54 -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 DCB97B825E4; Wed, 19 Oct 2022 20:30:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C92CBC433C1; Wed, 19 Oct 2022 20:30:50 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="m3pCQfIb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1666211448; 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: in-reply-to:in-reply-to:references:references; bh=D096jznuqlRQwJxMQwcMaa14sQx4bVWfoMm54xn0QwQ=; b=m3pCQfIbed7QAmhdX5Jk66SkwkOn91IQAhAZCloMrDcuwuFU7hOeOzneYWAUG5sSS6MVh9 CpjbVwJu51bpOf06LYjFWzNjorxwsYs+Gh4OelaonRbAP4tuih3CtfS2Bz8UE4icXCx4/N YZsg/nNHc64iJoQTjaZiMFXW5qE/yN4= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 8a12f077 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 19 Oct 2022 20:30:47 +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 v2] kbuild: treat char as always unsigned Date: Wed, 19 Oct 2022 14:30:34 -0600 Message-Id: <20221019203034.3795710-1-Jason@zx2c4.com> In-Reply-To: References: 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?1747150345158847575?= X-GMAIL-MSGID: =?utf-8?q?1747150345158847575?= 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 make assumptions about `char` with no `signed` or `unsigned` specifier. 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 heisensign bugs entirely. Set `-funsigned-char` globally, so that gcc makes the type unsigned on all architectures. This will break things in some places and fix things in others, so this will likely cause a bit of churn while reconciling the type misuse. 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..bbf376931899 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 -funsigned-char \ -std=gnu11 KBUILD_CPPFLAGS := -D__KERNEL__ KBUILD_RUSTFLAGS := $(rust_common_flags) \