Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1579186pxb; Tue, 8 Feb 2022 22:59:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJxo/WpbbNutz12DdANWOJ9b/BJ75yPCdkxNyDx9LUnteqBkDb8bx4/LUnQfN6RrOT8cKdg7 X-Received: by 2002:a17:902:ec82:: with SMTP id x2mr849225plg.139.1644389970606; Tue, 08 Feb 2022 22:59:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644389970; cv=none; d=google.com; s=arc-20160816; b=r5Mliy5yQYBI0u40SbMrKvBURDoN9k3yRyeCR0FGKLlcDE3iPc/sPGGmRVsZ+HBFxo PY15Dkp3Two7PraokhA0r2VzL5UYEyEGI5QYXyFfA2S0GXtDjWjoauzQyC6MfoAV9s61 ejrtB35RYt59F9Dlv9sVwbosaYPx9ueXmYVODmyXhIeMXUwifeXKUC/qfR30fmYAVV+T lI3qwlZiLwPsQswwVuVM/1JvRw4qxhdGItupXNBP6X1jWw82LqzKLI05TIxkf767mI/w tPlCpVbNLnGgUXCmuq57PZR8Z/x9BXZ8ar12V8u/G7b6u+C3dSHhQRApXxxo1muJO5HM jmFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=MHD6q+Bg1CAZFEstaZFHsulOzcBrpeMzXQI3VG7uoNM=; b=eYKyw1wMVmdlBBEQxoJr0XqiXuB/LrPYLt5pUjUzse5XfexFtc02rW3821DeGnpJmP h2Yz+tdcSSKSpCo8pOdhMXU8AVS9kyLfj74OMYjqD69IiF0m6UgYSJKI1xANPf9K/gH1 1V39Xw63ZzaAUn5Ke5vWzY9Hce3jXE+NpQVhh8x0KyWGuSsMoMUYWsQrOtuJnQilfd10 ghKLq21FfPVz98RZAjD13iIxsEeH49xE0nCqZJN+nBOucpp3mHlrM3FA9DY5f07Ogek/ 2DFsb1AYuTd0VkMArI4tO4HN+sxhC/7lOIgqa072iZoujJX8YlZkEehrfT2eiGHI22YY FL6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=XJRcGlNT; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id bm1si4645209pgb.705.2022.02.08.22.59.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 22:59:30 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=XJRcGlNT; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D6D2AC002B6B; Tue, 8 Feb 2022 22:25:25 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346064AbiBHDJh (ORCPT + 99 others); Mon, 7 Feb 2022 22:09:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238531AbiBHDJf (ORCPT ); Mon, 7 Feb 2022 22:09:35 -0500 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5E9AC061A73 for ; Mon, 7 Feb 2022 19:09:34 -0800 (PST) Received: by mail-pj1-x1033.google.com with SMTP id a11-20020a17090a740b00b001b8b506c42fso980649pjg.0 for ; Mon, 07 Feb 2022 19:09:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=MHD6q+Bg1CAZFEstaZFHsulOzcBrpeMzXQI3VG7uoNM=; b=XJRcGlNT0cBC2DmG39HOUGpo9qN5/1Cz3pdW6NxY6e/wELu6IC29R0W/n3DdG6Kc8s YnyWU10ZuVrBs1aFfIiLaun5+HIaEKTMS+fp5dQEZCOuiYAa4fcJg+XaX9aoducLDvRz IKMl9X7l6jvykRysYNEIixCpuActzIJVqC6I4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=MHD6q+Bg1CAZFEstaZFHsulOzcBrpeMzXQI3VG7uoNM=; b=AkzMWzdfivFmn3ufpfYlvtL87qz+n4Mt5vujYEUiz4/H8pzC3MENRholBCcQvRAKZ+ B5gLlRpRy2tyx7s96RWf28jLD0UQ91PQL1LOmVeiE0f5/J8rD7BRXtUKXem8rD1VSDbG o26IjNVkyVa/UXdOUwzwwaihkvEab3W5uxrMGIs5vMwKP0MCBFfq1yUQz414dv4oVZQ5 BIzx4B32qV/JD68MThDlAROIVe4eKy1pldJ0fAAfy+QS2uQNabfIaJvoTO3DI5i+GqWR qgav9DX44UilmgoajWOhldc4KXLuRR/c36P9qWxCqjoplg6CwBj4mfp0PWuBdCQ7JEAQ xwgg== X-Gm-Message-State: AOAM533uvh8qtCuZTrW7IBO1dlC+K7tYY8Xpbd84QHmabQ7bK0fCfJ3r 5MtvDdb1qAoA2sSXZ993VYGe1Q== X-Received: by 2002:a17:902:f70c:: with SMTP id h12mr2557265plo.53.1644289774153; Mon, 07 Feb 2022 19:09:34 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id n13sm10099487pfv.212.2022.02.07.19.09.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 19:09:33 -0800 (PST) Date: Mon, 7 Feb 2022 19:09:32 -0800 From: Kees Cook To: Nick Desaulniers Cc: Arvind Sankar , Fangrui Song , LKML , lkp@lists.01.org, lkp@intel.com, kernel test robot Subject: Re: [x86] 1099ce55b0: BUG:kernel_NULL_pointer_dereference,address Message-ID: <202202071858.0B5538E7CB@keescook> References: <20220204123740.GA4077@xsang-OptiPlex-9020> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 On Mon, Feb 07, 2022 at 04:23:06PM -0800, Nick Desaulniers wrote: > On Fri, Feb 4, 2022 at 4:37 AM kernel test robot wrote: > > FYI, we noticed the following commit (built with clang-15): > > > > commit: 1099ce55b0530ff429312dc37362ad43aee8c5c0 ("x86: don't build CONFIG_X86_32 as -ffreestanding") > > https://git.kernel.org/cgit/linux/kernel/git/kees/linux.git for-next/memcpy > > > > in testcase: boot > [...] > I've been having a hard time pinpointing via bisection when this > stopped working. I suspect it's actually the change on llvm's side > that would replace memcmp with bcmp. With this diff, we can boot > ARCH=i386 defconfig Thanks for spending the time on this! > > ``` > diff --git a/arch/x86/Makefile b/arch/x86/Makefile > index 7ef211865239..5e4570495206 100644 > --- a/arch/x86/Makefile > +++ b/arch/x86/Makefile > @@ -88,6 +88,8 @@ ifeq ($(CONFIG_X86_32),y) > include $(srctree)/arch/x86/Makefile_32.cpu > KBUILD_CFLAGS += $(cflags-y) > > + KBUILD_CFLAGS += -fno-builtin-bcmp > + > ifeq ($(CONFIG_STACKPROTECTOR),y) > ifeq ($(CONFIG_SMP),y) > KBUILD_CFLAGS += > -mstack-protector-guard-reg=fs > -mstack-protector-guard-symbol=__stack_chk_guard > ``` > > It looks like the call argument setup in the _callers_ of memcmp is messed up. > > Before: > pushl %ecx > pushl %ebx > pushl -24(%ebp) > calll bcmp > > After: > movl %ebx, %eax > movl %esi, %edx > movl %ecx, %ebx > calll memcmp > > it looks like they're not obeying `-mregparm=3`. > > https://godbolt.org/z/z3fjveP4h > > Diffing the IR between `-mregparm=3` vs not, it looks like there's an > LLVM IR function argument attribute inreg. > https://llvm.org/docs/LangRef.html#parameter-attributes > >> This indicates that this parameter or return value should be treated in a > >> special target-dependent fashion while emitting code for a function call > >> or return (usually, by putting it in a register as opposed to memory, > >> though some targets use it to distinguish between two different kinds of > >> registers). Use of this attribute is target-specific. > > As is tradition, instcombine is not checking+carrying over the > function argument attributes when replacing calls to memcmp w/ bcmp. > > Before: > %4 = call i32 @memcmp(i8* inreg noundef %3, i8* inreg noundef %0, > i32 inreg noundef %1) #4, !dbg !22 > > After: > %bcmp = call i32 @bcmp(i8* %3, i8* %0, i32 %1), !dbg !22 > > Filed: > https://github.com/llvm/llvm-project/issues/53645 > > So I think the best course of action is to disable memcmp to bcmp > BEFORE the removal of -ffreestanding, and only for clang until we have > a fix in hand. What do you mean about BEFORE the removal of -ffreestanding? As in, add two patches, one to add -fno-builtin-bcmp and the next to remove -ffreestanding? i.e.: diff --git a/arch/x86/Makefile b/arch/x86/Makefile index e84cdd409b64..c92f69e916b4 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -90,6 +90,9 @@ ifeq ($(CONFIG_X86_32),y) # temporary until string.h is fixed KBUILD_CFLAGS += -ffreestanding + ifdef CONFIG_CC_IS_CLANG + KBUILD_CFLAGS += -fno-builtin-bcmp + endif ifeq ($(CONFIG_STACKPROTECTOR),y) ifeq ($(CONFIG_SMP),y) then: diff --git a/arch/x86/Makefile b/arch/x86/Makefile index c92f69e916b4..f56936aeed9e 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -88,8 +88,6 @@ ifeq ($(CONFIG_X86_32),y) include $(srctree)/arch/x86/Makefile_32.cpu KBUILD_CFLAGS += $(cflags-y) - # temporary until string.h is fixed - KBUILD_CFLAGS += -ffreestanding ifdef CONFIG_CC_IS_CLANG KBUILD_CFLAGS += -fno-builtin-bcmp endif ? -- Kees Cook