Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1712860ybt; Mon, 15 Jun 2020 07:34:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7CZv7RYuO0ceSAuPVW6rCKW/QFpq7RMit4TGKZoUJzK4NIJXbjwoORrxNnUt/OR21CweC X-Received: by 2002:a17:906:5496:: with SMTP id r22mr27153164ejo.449.1592231693473; Mon, 15 Jun 2020 07:34:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592231693; cv=none; d=google.com; s=arc-20160816; b=Uz4yJH5h1Czjk53JJsi01WFgIs5jm5EsXBoxq1BTonG9NH21Ujtd+YxA62wYWHitjZ 9a+q2CVOJj9UJOEW1AK0wMUoYOqT1Zj6NkpKyk6A5rUVSyD4o4KpkKFeoTLRY01hK6oh ZWk0iSmBhnHgg3pED+9wqxmTd+ElnxhiRoTeg9bqQz+ZI9txm9CxtakDXo/hi5o6++Nm 0/kI2VOBhOgmbuvtDorMy1UEiEh+mCBG+84scAVNn9aLFX+bQs6VFAI+50kjjN6WbtnT MyOtTWH6zm9oHAHKsdiksVSOZGDGp0zcoPRSXhYXos6AMu+l9HD2bn8+QL8tz7i+P35W WilQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=iVtDey7osCTiXRlBck0DMsdzE3CHMm8eourPYCpuPzc=; b=TOGv2n5maJpEQ72VvfZktsqWwH5nrE3qrlCVw773yUjwvDTTr9fBUEM9Sa50brCglC mWVmw7AHnwhM6JLwL/ZSq+ITnJJ6QN+q7/uaW4JnyZAExOoRC5o15LINlZ7p+vEuRiku YcT+f931lvvOoa3PDovpYn+zIa396TxES/abBLmFZ1Ir4eMOxUzkJDjjq3JHno030j0x b8ycg0Lwx6xRDctwVsIF0aHRFhutBkxrXUGVkjdqiJUGqvM0oLDZaNQoVN7134WCnQDt 7/k/RlSi6iw/R1/zp/dAqryYWdgXe/zext0Kcw79pMSq2ETKE10MLy+4gA4kp3Na3gUm 6//Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=RCpCMYm2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e23si8845527ejb.425.2020.06.15.07.34.30; Mon, 15 Jun 2020 07:34:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=RCpCMYm2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730214AbgFOOa1 (ORCPT + 99 others); Mon, 15 Jun 2020 10:30:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728773AbgFOOa0 (ORCPT ); Mon, 15 Jun 2020 10:30:26 -0400 Received: from merlin.infradead.org (unknown [IPv6:2001:8b0:10b:1231::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C981C061A0E for ; Mon, 15 Jun 2020 07:30:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=iVtDey7osCTiXRlBck0DMsdzE3CHMm8eourPYCpuPzc=; b=RCpCMYm2KeErVoebP4brd4PoGi 8yHqF1nw5116S5QlkbTgcv1ndddUSk/wdK2PhHx8a71YiqLpVTyet3gUwfa11lix7lqVjcZex+NPC IRuT3MmjG+QSK+64UJ/3IkBoiR+aSdvnJdD4ThmJNchHTAEqLjVBI9uwzTe3LMwwrEa0+gNI8dOoS cWinMea+XtydP4bIfhwgzGUCRwMWTdlwtU9PdZQGrb7HD034NhQf7KAKZt7rqWZ45zBz5IuvDHAmH XDjVO1Wtan9nx5b+XfZz185gMi+QPJPNPbijylin4cMCKy1vYTY65V85ALDVuS7iXQ9Qdh93LeWxa Kfq91ipg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jkq7W-0006Eh-6c; Mon, 15 Jun 2020 14:29:54 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 1BBA33028C8; Mon, 15 Jun 2020 16:29:50 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 09DC3203B8172; Mon, 15 Jun 2020 16:29:50 +0200 (CEST) Date: Mon, 15 Jun 2020 16:29:49 +0200 From: Peter Zijlstra To: Marco Elver Cc: Dmitry Vyukov , Andrey Konovalov , Mark Rutland , Borislav Petkov , Thomas Gleixner , Ingo Molnar , clang-built-linux , "Paul E. McKenney" , Alexander Potapenko , kasan-dev , LKML , the arch/x86 maintainers , Andrew Morton , Josh Poimboeuf Subject: Re: [PATCH -tip v3 1/2] kcov: Make runtime functions noinstr-compatible Message-ID: <20200615142949.GT2531@hirez.programming.kicks-ass.net> References: <20200608110108.GB2497@hirez.programming.kicks-ass.net> <20200611215538.GE4496@worktop.programming.kicks-ass.net> <20200612114900.GA187027@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 15, 2020 at 09:53:06AM +0200, Marco Elver wrote: > > Disabling KCOV for smp_processor_id now moves the crash elsewhere. In > the case of KASAN into its 'memcpy' wrapper, called after > __this_cpu_read in fixup_bad_iret. This is making me suspicious, > because it shouldn't be called from the noinstr functions. With your .config, objtool complains about exactly that though: vmlinux.o: warning: objtool: fixup_bad_iret()+0x8e: call to memcpy() leaves .noinstr.text section The utterly gruesome thing below 'cures' that. > For KCSAN the crash still happens in check_preemption_disabled, in the > inlined native_save_fl function (apparently on its 'pushf'). If I turn > fixup_bad_iret's __this_cpu_read into a raw_cpu_read (to bypass > check_preemption_disabled), no more crash with KCSAN. vmlinux.o: warning: objtool: debug_smp_processor_id()+0x0: call to __sanitizer_cov_trace_pc() leaves .noinstr.text section vmlinux.o: warning: objtool: check_preemption_disabled()+0x1f: call to __sanitizer_cov_trace_pc() leaves .noinstr.text section vmlinux.o: warning: objtool: __this_cpu_preempt_check()+0x4: call to __sanitizer_cov_trace_pc() leaves .noinstr.text section That could be either of those I suppose, did you have the NOP patches on? Let me try... those seem to placate objtool at least. I do see a fair amount of __kasan_check*() crud though: vmlinux.o: warning: objtool: rcu_nmi_exit()+0x44: call to __kasan_check_read() leaves .noinstr.text section vmlinux.o: warning: objtool: rcu_dynticks_eqs_enter()+0x1c: call to __kasan_check_write() leaves .noinstr.text section vmlinux.o: warning: objtool: rcu_nmi_enter()+0x46: call to __kasan_check_read() leaves .noinstr.text section vmlinux.o: warning: objtool: rcu_dynticks_eqs_exit()+0x21: call to __kasan_check_write() leaves .noinstr.text section vmlinux.o: warning: objtool: __rcu_is_watching()+0x1c: call to __kasan_check_read() leaves .noinstr.text section vmlinux.o: warning: objtool: debug_locks_off()+0x1b: call to __kasan_check_write() leaves .noinstr.text section That wasn't supported to happen with the __no_sanitize patches on (which I didn't forget). Aah, I think we've lost a bunch of patches.. /me goes rummage. This: https://lkml.kernel.org/r/20200603114051.896465666@infradead.org that cures the rcu part of that. Let me go look at your KCSAN thing now... --- diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index af75109485c26..031a21fb5a741 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -675,6 +675,14 @@ struct bad_iret_stack { struct pt_regs regs; }; +void __always_inline __badcpy(void *dst, void *src, int nr) +{ + unsigned long *d = dst, *s = src; + nr /= sizeof(unsigned long); + while (nr--) + *(d++) = *(s++); +} + asmlinkage __visible noinstr struct bad_iret_stack *fixup_bad_iret(struct bad_iret_stack *s) { @@ -690,13 +698,13 @@ struct bad_iret_stack *fixup_bad_iret(struct bad_iret_stack *s) (struct bad_iret_stack *)__this_cpu_read(cpu_tss_rw.x86_tss.sp0) - 1; /* Copy the IRET target to the temporary storage. */ - memcpy(&tmp.regs.ip, (void *)s->regs.sp, 5*8); + __badcpy(&tmp.regs.ip, (void *)s->regs.sp, 5*8); /* Copy the remainder of the stack from the current stack. */ - memcpy(&tmp, s, offsetof(struct bad_iret_stack, regs.ip)); + __badcpy(&tmp, s, offsetof(struct bad_iret_stack, regs.ip)); /* Update the entry stack */ - memcpy(new_stack, &tmp, sizeof(tmp)); + __badcpy(new_stack, &tmp, sizeof(tmp)); BUG_ON(!user_mode(&new_stack->regs)); return new_stack;