Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3229405imu; Sat, 24 Nov 2018 00:36:37 -0800 (PST) X-Google-Smtp-Source: AFSGD/U9GrJATVPJHxH3h8+raRyIC2aZE/adB2WIdz97z1DCvzFDkEsibQrklRRwWIdNaI60vQZf X-Received: by 2002:a63:6b08:: with SMTP id g8mr17018507pgc.119.1543048596943; Sat, 24 Nov 2018 00:36:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543048596; cv=none; d=google.com; s=arc-20160816; b=zI0ev1mYCXwa1bCRifJNu+/VhPQhtBO+JNdQf3BL6KircQDmjaxphnfXU9aRVt62Rr /AzykLl08bLyt84xs9XAKHG7UfeUC0liTFUTJ7T3f/Eu9Yj7QCBDbougbx9r7DChHhcu rNLN2wmb5Q+UllSwgUl4RAFmPjOB1Go5EvXJcnXicgBWP6BxM7TAbdOZ1M49iWRg2QVF 0/TGRK8NJz49Znyv0cr73h58SUSZTIl+SYjO2d0K+zVr95MrjCu2oNyERVeeP2ljzoLx R3eN4x1+hLNDV1QCFykJUnVQRWUo98uWGWkatxsVVtu1rRN1XosS+d/+dxuh2dg7jhQ8 sjVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=2YIi5jQvgMpuGlHKdnsNyNfFz9fVxRNiM+P1Efnijvs=; b=j5mq4B8qae3NxCVjzytKDBEJUZ01JnP10r92v2rnu6Ch1GF11mLjpXdbbvyEUiMZFk jyFIuDD5qE+Rdrpc7J+efAdgiT2Hgsa1tkg5TFygzQ7peoCGrnFdGcSAJZxIinyGFIzk gzcPmeK6EEW3VP9nRjXu0QRqg2zv02zXIPSm6bpqY4ef33xpuQNaeLhVatb9Jmw+N9/m hu9RuANwRNCTVSeLdPWmhjnnIfRsyJNlAg9xRazfgV3B3+Fc/ZNAIVYP6xnlG+JDV0vu nmuUG/iwL4yKuW9dMZTcmdoUyWg0lwItP686Ls/KOi/23iyGJ9UKWKlPcaXh9hfJUOTf Fjwg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r25si16166193pfk.28.2018.11.24.00.36.22; Sat, 24 Nov 2018 00:36:36 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2394977AbeKXA7l (ORCPT + 99 others); Fri, 23 Nov 2018 19:59:41 -0500 Received: from bran.ispras.ru ([83.149.199.196]:28112 "EHLO smtp.ispras.ru" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388230AbeKXA7l (ORCPT ); Fri, 23 Nov 2018 19:59:41 -0500 X-Greylist: delayed 513 seconds by postgrey-1.27 at vger.kernel.org; Fri, 23 Nov 2018 19:59:40 EST Received: from monopod.intra.ispras.ru (monopod.intra.ispras.ru [10.10.3.121]) by smtp.ispras.ru (Postfix) with ESMTP id 8CDD920AA2; Fri, 23 Nov 2018 17:06:40 +0300 (MSK) Date: Fri, 23 Nov 2018 17:06:38 +0300 (MSK) From: Alexander Monakov To: Alexander Popov cc: Florian Weimer , Richard Sandiford , Segher Boessenkool , Kees Cook , Ingo Molnar , Andy Lutomirski , Tycho Andersen , Laura Abbott , Mark Rutland , Ard Biesheuvel , Borislav Petkov , Thomas Gleixner , "H . Peter Anvin" , Peter Zijlstra , Emese Revfy , Thomas Garnier , Alexei Starovoitov , Masami Hiramatsu , "David S . Miller" , Steven Rostedt , Dave Hansen , Will Deacon , Jann Horn , linux-arm-kernel@lists.infradead.org, LKML , "kernel-hardening@lists.openwall.com" , gcc@gcc.gnu.org Subject: Re: Investigating a stack state mismatch in Linux kernel In-Reply-To: <57225f38-3f6d-4029-8f89-4b6eba97c3c1@linux.com> Message-ID: References: <875zwyabac.fsf@oldenburg.str.redhat.com> <2a2b1181-2175-7e4e-189c-12630f43d10d@linux.com> <57225f38-3f6d-4029-8f89-4b6eba97c3c1@linux.com> User-Agent: Alpine 2.20.13 (LNX 116 2015-12-14) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Wed, 21 Nov 2018, Alexander Popov wrote: > Hello everyone! > > At irc.freenode.org/#gcc people told me that I should CC gcc@gcc.gnu.org to get > some attention of gcc developers. > > Link to previous discussion: > https://www.openwall.com/lists/kernel-hardening/2018/11/14/1 So just for information, it isn't a plugin bug. I'll elaborate below, but in short, objtool was complaining about unreachable code. To be fair though, gcc could have made the problem easier to spot. Now for the details. The repro uses an unusual (randomized) kernel config, in particular gcov is enabled and NR_CPUS is 1. Thus we have static int duplicate_processor_ids[] = { [0 ... 1 - 1] = -1, }; and the compiler deduces that the loop in acpi_duplicate_processor_id does not iterate: bool acpi_duplicate_processor_id(int proc_id) { int i; for (i = 0; i < nr_duplicate_ids; i++) { if (duplicate_processor_ids[i] == proc_id) return true; } return false; } However as gcov is enabled, loop backedge remains, followed by gcov counter increment and __builtin_unreachable() (on GIMPLE). On RTL, however, the basic block with the increment ends with a barrier rtx, which is not visible in assembly and looks just as if control flow falls through to a function exit. Since the exit in question corresponds to a shrink-wrapped early exit that does not push/pop registers, objtool complains. Ultimately this is poor luck, if gcc optimized the code better or terminated the block that-should-not-be-reached with ud2, it would not arise. Alexander