Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2004471ybh; Fri, 17 Jul 2020 07:06:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzYflqN/1bCOHt5obVZ18bxThEkBXMEG0A+Ql7UXZdeszWUBm7xSaOXvUNmTZIlzoWOPxBm X-Received: by 2002:a17:906:1c05:: with SMTP id k5mr8509115ejg.320.1594994775997; Fri, 17 Jul 2020 07:06:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594994775; cv=none; d=google.com; s=arc-20160816; b=SUWxddHUuivlulGQNx7xiBZWtyMbdEsYfZ3LJZgfrl/f9felnEXAZtUgUvVqLJBE1i 6mldmi1Z/MAc2ydCJFhKxaLlJd7/0DclBNUBUcc4dOqIJH9CBT0AYJMaG6uDzxg6/p5C jPJ0q+9LyzGGGuAqkjmhYjrGLEd1uMR3moKv9fzL+tnq/hR1NpAfg6SY4nvdeN9GOAQP WbHyZSU4QRV7LUtqGzrGZXl1ZetcHtMx2LC4Qef90P2TrJYQws+iowGKYkF4f4RfiiSu j4bDzv368nnkPeRFXU6GWbM06bodCDCGa7CNFNhz7gOzYrh/b+xm6WCpsQOub1OTrPAj d6EA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=IMwwAUUq0OOq0OaEDBeXqYJMF/5C2zNXBqYrD8iYPjE=; b=e66PkHLDMHXgMR+bJ3ITPUa/qD31dsKz+iPJ19NHKMCnvYHNSLRePKlXnIb2uvj5Vf U7IajgrioaIJIIOV0tpX/vqaFmyLtAZxHK+4QIPaolYCQkbUnnqVDRdNZLTZakETBeAe Zrgfu+NgH2OegNo1yVZAIcz5KkZrXltiHolBAO8extR6nDaA6p3FZr1mE52dNwv+9tDC lB3uyFSuUQKDRHXcpmKbPzraY5Y28Zoc+ykwXsLuEpjCTfTARvtixBU1YTdvbTS6qbne H1TW0oJ5/IsPDQtRs+PsMm4hvA0Chpp2riRdmbBfugaLP2zgg7J9c7Roxdvl05wIJgAx QtGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LQW8oWCk; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t17si5766246ejs.635.2020.07.17.07.05.52; Fri, 17 Jul 2020 07:06:15 -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=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LQW8oWCk; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727050AbgGQOEg (ORCPT + 99 others); Fri, 17 Jul 2020 10:04:36 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:38057 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726988AbgGQOEf (ORCPT ); Fri, 17 Jul 2020 10:04:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594994675; 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=IMwwAUUq0OOq0OaEDBeXqYJMF/5C2zNXBqYrD8iYPjE=; b=LQW8oWCkDxdl6AoCxMc0x55edwXEYW0Pek9b6TVgI/GoNy901ZvJQv4BAd9iI/6kiIgras 19twrTMJUYpUhWcERmnJ7fg/gB2LMyUXLLB/hh//e3dNOvJf1Wfssqqznrv7k51gCbz/R4 mSkzpByqiTedopvwjA2twXyUZkqq9IY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-216-tmrvOvS_O_y94gYCONtZug-1; Fri, 17 Jul 2020 10:04:32 -0400 X-MC-Unique: tmrvOvS_O_y94gYCONtZug-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4CC901080; Fri, 17 Jul 2020 14:04:31 +0000 (UTC) Received: from treble.redhat.com (ovpn-118-144.rdu2.redhat.com [10.10.118.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F55F1EA; Fri, 17 Jul 2020 14:04:30 +0000 (UTC) From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Peter Zijlstra , Wang ShaoBo Subject: [PATCH 1/2] x86/unwind/orc: Fix ORC for newly forked tasks Date: Fri, 17 Jul 2020 09:04:25 -0500 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The ORC unwinder fails to unwind newly forked tasks which haven't yet run on the CPU. It correctly reads the 'ret_from_fork' instruction pointer from the stack, but it incorrectly interprets that value as a call stack address rather than a "signal" one, so the address gets incorrectly decremented in the call to orc_find(), resulting in bad ORC data. Fix it by forcing 'ret_from_fork' frames to be signal frames. Reported-by: Wang ShaoBo Signed-off-by: Josh Poimboeuf --- arch/x86/kernel/unwind_orc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/unwind_orc.c b/arch/x86/kernel/unwind_orc.c index 7f969b2d240f..ec88bbe08a32 100644 --- a/arch/x86/kernel/unwind_orc.c +++ b/arch/x86/kernel/unwind_orc.c @@ -440,8 +440,11 @@ bool unwind_next_frame(struct unwind_state *state) /* * Find the orc_entry associated with the text address. * - * Decrement call return addresses by one so they work for sibling - * calls and calls to noreturn functions. + * For a call frame (as opposed to a signal frame), state->ip points to + * the instruction after the call. That instruction's stack layout + * could be different from the call instruction's layout, for example + * if the call was to a noreturn function. So get the ORC data for the + * call instruction itself. */ orc = orc_find(state->signal ? state->ip : state->ip - 1); if (!orc) { @@ -662,6 +665,7 @@ void __unwind_start(struct unwind_state *state, struct task_struct *task, state->sp = task->thread.sp; state->bp = READ_ONCE_NOCHECK(frame->bp); state->ip = READ_ONCE_NOCHECK(frame->ret_addr); + state->signal = (void *)state->ip == ret_from_fork; } if (get_stack_info((unsigned long *)state->sp, state->task, -- 2.25.4