From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 777D4C433EF for ; Thu, 16 Sep 2021 21:06:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4DFD160C51 for ; Thu, 16 Sep 2021 21:06:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239995AbhIPVIR (ORCPT ); Thu, 16 Sep 2021 17:08:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232910AbhIPVIP (ORCPT ); Thu, 16 Sep 2021 17:08:15 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D703FC061574 for ; Thu, 16 Sep 2021 14:06:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=N43Uhgo0DQNKmivJ+AXtrxW74Hb4By7l9dPAXojWeVc=; b=XrcTetY4cT0UHFn/qggyPEfWyM z3LnQwp1BkT1Y6330gBshWLxNOHkuXhvn5OHbYDdj1catBmE2Tf3h2QtwVY/dTyTDVYq+9N9F1ndL FsJJJPHZh/HyU1eMv3YQ0y44bKD/Ap8RyWoYn5sDu0cEv6AA3sYJN5PAzZjOWLOuaIRGk9mLahi0L tspgbyyehsvMljrPKevszqAfI8SOUC+iE6evVDOVo3wWkF5AtzDwUCM/46cdRWdd+9Ae4WBVCcr0S 1kxYBomck1PsaWpbAK3nm4JrDvZpdckkG2j/g1+i5eyblI0JNJAVtB5P8arDLN7D9FvTM7nHlxsZr vtgAJaFg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=worktop.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mQyZC-00HFYv-H3; Thu, 16 Sep 2021 21:05:22 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id B61DA98625E; Thu, 16 Sep 2021 23:05:09 +0200 (CEST) Date: Thu, 16 Sep 2021 23:05:09 +0200 From: Peter Zijlstra To: Ondrej Zary Cc: Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: IOPL emulation breaks hpasmd (hp-health) needed by HP DL380 G4 servers Message-ID: <20210916210509.GG4323@worktop.programming.kicks-ass.net> References: <202109151423.43604.linux@zary.sk> <87pmt8a1mc.ffs@tglx> <202109162227.17415.linux@zary.sk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202109162227.17415.linux@zary.sk> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 16, 2021 at 10:27:17PM +0200, Ondrej Zary wrote: > (gdb) run > Starting program: /opt/hp/hp-health/bin/IrqRouteTbl > > Program received signal SIGSEGV, Segmentation fault. > 0xf7fc509b in ?? () > (gdb) bt > #0 0xf7fc509b in ?? () > #1 0x08048848 in ?? () > #2 0x08048aa1 in ?? () > #3 0x08048e05 in ?? () > #4 0xf7df9e46 in __libc_start_main () from /lib32/libc.so.6 > #5 0xf7ffd000 in ?? () from /lib/ld-linux.so.2 > Backtrace stopped: previous frame inner to this frame (corrupt stack?) > (gdb) x/3i $pc > => 0xf7fc509b: cli > 0xf7fc509c: push %ebp > 0xf7fc509d: mov %esp,%ebp > > OMG, maybe is it calling into the mmapped BIOS area? Lol... does something like the below (which *really* wants to be behind something like sysctl.iopl_fake_if) work for you? --- diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index a58800973aed..55c3904e656d 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -528,6 +528,34 @@ static enum kernel_gp_hint get_kernel_gp_address(struct pt_regs *regs, #define GPFSTR "general protection fault" +bool fixup_iopl_exception(struct pt_regs *regs) +{ + struct thread_struct *t = ¤t->thread; + unsigned char buf[MAX_INSN_SIZE]; + struct insn insn; + int nr_copied; + + if (!IS_ENABLED(CONFIG_X86_IOPL_IOPERM) || t->iopl_emul != 3 || !regs) + return false; + + nr_copied = insn_fetch_from_user(regs, buf); + if (nr_copied <= 0) + return false; + + if (!insn_decode_from_regs(&insn, regs, buf, nr_copied)) + return false; + + if (insn.length != 1) + return false; + + if (insn.opcode.bytes[0] != 0xfa && + insn.opcode.bytes[0] != 0xfb) + return false; + + regs->ip += 1; + return true; +} + DEFINE_IDTENTRY_ERRORCODE(exc_general_protection) { char desc[sizeof(GPFSTR) + 50 + 2*sizeof(unsigned long) + 1] = GPFSTR; @@ -553,6 +581,9 @@ DEFINE_IDTENTRY_ERRORCODE(exc_general_protection) tsk = current; if (user_mode(regs)) { + if (fixup_iopl_exception(regs)) + goto exit; + tsk->thread.error_code = error_code; tsk->thread.trap_nr = X86_TRAP_GP;