Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp829088pxu; Thu, 3 Dec 2020 13:49:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJyVFsBkz1fL6tp0TYewkHhGv1eF2W56xOo+05lW5ce39cN0gBlLx9finpw29UHdR8VDuFeJ X-Received: by 2002:a17:906:17d9:: with SMTP id u25mr4508801eje.34.1607032167476; Thu, 03 Dec 2020 13:49:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607032167; cv=none; d=google.com; s=arc-20160816; b=j/3h6Hc+OCFSgA7IE+4Pf/Rtt4R93UMhsUhdtAEUBjeD5myP6VPiIOMB8Ftl1Q32RG oOYa/HRX1WOQhd7oXHYZMSOKlvuGiLoCvktYn0TkswwK88Kfmpc14/ZVu3TZfHv+IYYF 9BTwkP7E5fJ9eduJRM3WXCIBPcE8/SZ2qUFH6UC+OLg0aN17ASUT385FwJssEnb3A3he Hu8RNa+Iq0MuIUd1kXeJ8WzSsVdEBB6m/9TDBfSNZxT16yc6VLfsZbdK0I3RbXCOQAPX 0ntkcGNy65E5Pxp5oy3I18CErzWShzrLabWy6hNNf/b9rxSR0qLtnJsM6dC4j0LNB4lq BRGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition:mime-version :message-id:subject:cc:to:from:date; bh=pDXFKHV7rrY7Aw0tF+7CjEqfwMmffW4mxOoVCreuoy0=; b=fvXUQkiso3fmaHMNkWgpfsTIKvNwwyonMhWk2t/0JLFwATSfOUiHMl0/W5sZmfgTPt MNOJblLOAg651pE2XaXK7SjMiMlr2JilGObJYlcyAH3Io6sh6oxwaI12E7Op7duwGzl7 ZMd0EgxlV4/0FMLofn8qAtuxHZ2r+INfvtgYW76rsrkmDo+uQ9XwMrrGMjsDvNDi25J8 wdKoWPiN2PDfrPhKyZ7/eolq1GLU0VCA+6lO9Enxmoz7Um0uJCp8DQ0rLybspWJAYq+r mSyWzp3Kk7Ml1/SdG5aQ9P9gDPZN7Ap1Jm27ARcBbv9u9HbIstsU1Zibaekf2AQDd8wR qT6g== ARC-Authentication-Results: i=1; mx.google.com; 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 n20si1711889edw.72.2020.12.03.13.49.04; Thu, 03 Dec 2020 13:49:27 -0800 (PST) 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; 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 S1729489AbgLCVqR (ORCPT + 99 others); Thu, 3 Dec 2020 16:46:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726917AbgLCVqQ (ORCPT ); Thu, 3 Dec 2020 16:46:16 -0500 Received: from ZenIV.linux.org.uk (zeniv.linux.org.uk [IPv6:2002:c35c:fd02::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E1B7C061A4F; Thu, 3 Dec 2020 13:45:36 -0800 (PST) Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kkwPp-00GJPP-Nl; Thu, 03 Dec 2020 21:45:29 +0000 Date: Thu, 3 Dec 2020 21:45:29 +0000 From: Al Viro To: Linus Torvalds Cc: linux-kernel@vger.kernel.org, x86@kernel.org, linux-mips@vger.kernel.org, Randy Dunlap Subject: [PATCHSET] saner elf compat Message-ID: <20201203214529.GB3579531@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Sender: Al Viro Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This series deals with the warts in ELF compat on triarch architectures (x86_64 and mips64, that is). x86_64 at least does use compat_binfmt_elf.c for both 32bit ABIs; the way it is done is ugly as hell, though, and more than slightly brittle (see asm/compat.h for PRSTATUS_SIZE and SET_PR_FPVALID definitions - IMO that kind of magic is too ugly to live). mips64, OTOH, does not use compat_binfmt_elf.c for either of its 32bit ABIs. It has a couple of analogues (each with include of ../../../fs/binfmt_elf.c, BTW), with quite a bit of ancient cruft accumulated in those. Fortunately, cleanup of i386/x32 mess (first 3 commits in the series) provides a fairly straightforward way for mips64 to use fs/compat_binfmt_elf.c for both n32 and o32. That stuff had been sitting around since June; lately rdd has spotted Kconfig problems around COMPAT_BINFMT_ELF selects. All of them had been on configs that had COMPAT_BINFMT_ELF != COMPAT && BINFMT_ELF. For most of the architectures that's impossible to achieve, but some (sparc, e.g.) can end up with that. Randy posted a patch adding if BINFMT_ELF to selects that lacked it, but that looked wrong to me - why not centralize that logics into fs/Kconfig.binfmt? IOW, what's the point of having any such selects in arch/*/Kconfig? The answer (for mainline) is that mips compat does *NOT* want COMPAT_BINFMT_ELF. Not a problem with that series, though, so I'd retested it (seems to work, both for x86_64 and mips64, execs and coredumps for all ABIs alike), with centralization of Kconfig logics thrown in. It's based at 5.10-rc1 and lives in git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs.git#work.elf-compat I'll post the individual patches in followups. Shortlog: binfmt_elf: partially sanitize PRSTATUS_SIZE and SET_PR_FPVALID elf_prstatus: collect the common part (everything before pr_reg) into a struct [elfcore-compat][amd64] clean PRSTATUS_SIZE/SET_PR_FPVALID up properly mips binfmt_elf*32.c: use elfcore-compat.h mips: kill unused definitions in binfmt_elf[on]32.c mips: KVM_GUEST makes no sense for 64bit builds... mips compat: don't bother with ELF_ET_DYN_BASE mips: don't bother with ELF_CORE_EFLAGS mips compat: switch to compat_binfmt_elf.c Kconfig: regularize selection of CONFIG_BINFMT_ELF Diffstat: arch/Kconfig | 3 + arch/arm64/Kconfig | 1 - arch/ia64/kernel/crash.c | 2 +- arch/mips/Kconfig | 8 +-- arch/mips/include/asm/elf.h | 56 +++++---------- arch/mips/include/asm/elfcore-compat.h | 29 ++++++++ arch/mips/kernel/Makefile | 4 +- arch/mips/kernel/binfmt_elfn32.c | 106 ---------------------------- arch/mips/kernel/binfmt_elfo32.c | 109 ----------------------------- arch/mips/kernel/scall64-n64.S | 2 +- arch/parisc/Kconfig | 1 - arch/powerpc/Kconfig | 1 - arch/powerpc/platforms/powernv/opal-core.c | 6 +- arch/s390/Kconfig | 1 - arch/s390/kernel/crash_dump.c | 2 +- arch/sparc/Kconfig | 1 - arch/x86/Kconfig | 2 +- arch/x86/include/asm/compat.h | 11 --- arch/x86/include/asm/elfcore-compat.h | 31 ++++++++ fs/Kconfig.binfmt | 2 +- fs/binfmt_elf.c | 19 +++-- fs/binfmt_elf_fdpic.c | 22 ++---- fs/compat_binfmt_elf.c | 1 + include/linux/elfcore-compat.h | 15 +++- include/linux/elfcore.h | 7 +- kernel/kexec_core.c | 2 +- 26 files changed, 127 insertions(+), 317 deletions(-) create mode 100644 arch/mips/include/asm/elfcore-compat.h delete mode 100644 arch/mips/kernel/binfmt_elfn32.c delete mode 100644 arch/mips/kernel/binfmt_elfo32.c create mode 100644 arch/x86/include/asm/elfcore-compat.h