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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8CA5E77197 for ; Thu, 9 Jan 2025 17:17:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 578256B0082; Thu, 9 Jan 2025 12:17:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 528026B0083; Thu, 9 Jan 2025 12:17:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3F1D46B0085; Thu, 9 Jan 2025 12:17:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 154C56B0082 for ; Thu, 9 Jan 2025 12:17:24 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9142BC02D6 for ; Thu, 9 Jan 2025 17:17:23 +0000 (UTC) X-FDA: 82988569566.13.4428402 Received: from out03.mta.xmission.com (out03.mta.xmission.com [166.70.13.233]) by imf29.hostedemail.com (Postfix) with ESMTP id 1254C120008 for ; Thu, 9 Jan 2025 17:17:20 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; spf=pass (imf29.hostedemail.com: domain of ebiederm@xmission.com designates 166.70.13.233 as permitted sender) smtp.mailfrom=ebiederm@xmission.com; dmarc=pass (policy=none) header.from=xmission.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736443041; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FG4BHRak6Kv252fBf3C9AOpYb5RotoPnRULjh9dYIVw=; b=w8o+UKdyExABkzGOKY7omWWjUN1SCcVxb+ZfjitGqLFdds8u+reS+NawnUUwMac5vLiUoC 5QAxn6G8AA8h+X8TmgzTSl2K1tH6ZohBCYgXCTSOh+tzk56eoNA35Jcbbt/f1H/4UcxY2o i9HZv21T/14pspgbUthram2VqSjCcXg= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; spf=pass (imf29.hostedemail.com: domain of ebiederm@xmission.com designates 166.70.13.233 as permitted sender) smtp.mailfrom=ebiederm@xmission.com; dmarc=pass (policy=none) header.from=xmission.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736443041; a=rsa-sha256; cv=none; b=VPMMmVCiC+D0q/PA4pRTby0Drtu54NdjrGzlSraL1Oym2kUZOSa1lI+C38qpKwPoypu7uc XH0iYKq6EsI7xOQeSwYOxfkKjahEYsy5Aa54qkVAkVs/OwEQr5dh9nKhhOfF+q+yg+ETnz iZUgVmUgx/ovUBijFBBErLGz+NYNb4E= Received: from in02.mta.xmission.com ([166.70.13.52]:33594) by out03.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1tVw9l-004RzC-Sg; Thu, 09 Jan 2025 10:17:17 -0700 Received: from ip72-198-198-28.om.om.cox.net ([72.198.198.28]:57960 helo=email.froward.int.ebiederm.org.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1tVw9k-00FJDS-N8; Thu, 09 Jan 2025 10:17:17 -0700 From: "Eric W. Biederman" To: "Arnd Bergmann" Cc: "John Paul Adrian Glaubitz" , "Richard Henderson" , "Matt Turner" , "Kees Cook" , "Paul E. McKenney" , linux-alpha@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Michael Cree" , "Sam James" , "Maciej W. Rozycki" , "Geert Uytterhoeven" , "Michael Karcher" , "Chris Hofstaedtler" , util-linux@vger.kernel.org, linux-mips@vger.kernel.org, loongarch@lists.linux.dev References: <20250103140148.370368-1-glaubitz@physik.fu-berlin.de> <24f03227-1b55-4e50-b6e9-7ac74fda2602@app.fastmail.com> <678ee681-12c3-4e79-a04b-495daf343846@app.fastmail.com> <82d33a2d-dffe-4268-a175-4536b3f9c07f@app.fastmail.com> <87ed1cufj1.fsf@email.froward.int.ebiederm.org> <9b1749f0-e936-4bf5-90d6-8cf15e4f0ed9@app.fastmail.com> Date: Thu, 09 Jan 2025 11:17:09 -0600 In-Reply-To: <9b1749f0-e936-4bf5-90d6-8cf15e4f0ed9@app.fastmail.com> (Arnd Bergmann's message of "Thu, 09 Jan 2025 17:52:18 +0100") Message-ID: <87tta7uctm.fsf@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1tVw9k-00FJDS-N8;;;mid=<87tta7uctm.fsf@email.froward.int.ebiederm.org>;;;hst=in02.mta.xmission.com;;;ip=72.198.198.28;;;frm=ebiederm@xmission.com;;;spf=pass X-XM-AID: U2FsdGVkX1/xDtOyVhked4noljI67FlrAtmm9M6NllY= Subject: Re: [PATCH] alpha: Fix personality flag propagation across an exec X-SA-Exim-Connect-IP: 166.70.13.52 X-SA-Exim-Rcpt-To: loongarch@lists.linux.dev, linux-mips@vger.kernel.org, util-linux@vger.kernel.org, zeha@debian.org, kernel@mkarcher.dialup.fu-berlin.de, geert@linux-m68k.org, macro@orcam.me.uk, sam@gentoo.org, mcree@orcon.net.nz, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-alpha@vger.kernel.org, paulmck@kernel.org, kees@kernel.org, mattst88@gmail.com, richard.henderson@linaro.org, glaubitz@physik.fu-berlin.de, arnd@arndb.de X-SA-Exim-Mail-From: ebiederm@xmission.com X-SA-Exim-Scanned: No (on out03.mta.xmission.com); SAEximRunCond expanded to false X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 1254C120008 X-Rspam-User: X-Stat-Signature: 9njkh9t4czn8k95tt8hjf3fcenfuz793 X-HE-Tag: 1736443040-544269 X-HE-Meta: U2FsdGVkX1+QZOBSQ5MjGgNXGB5dI6MgkPj+gV3rWcP3NjHdQBk+MU2o+IQh4RJqL5iH2UFKusVmUbBg++V/JcY++xKJmghW4Lhv0KrCZVNX1FjzyaP4hBP7rmkXIwfJon4hTmIqB1cGIKoTxOoH+bpJJF6XRFgekc6JbaWNdGuXkrcKTA2X/63aqdwlVzgUHNH/RxZAgAHE1dNjqQxsPdL/91bx/UjyH0Hifw8rJY0mjVIZxcYtCAWKO7d+C+kE2yXe8sY2RocwQgFyneqmQPRDd5AbfdCd9bMpUnSJKKKW4vP7D/drJJS/CIFW9EqbFmsvOBkY9DyaXWIowMPfX6qwQSiEudGl8vWsxdKHuAdYo7W39Qo+65NtDss+pQu6MD6sKhuDlODm05fDFbgaVmUJgMCIO4HPwKYzfvm6Z7GDxu5qwLbzXxBTVElQEF0NyRVo7AscouhRHoyJGHao6xHgJiXXlY5zId+a5n/aA/LEShY2Z9fYq+JIe4pR3Q+/itZyATsX/GFAC/XyuKw7laY37V6dyqcMK7DzaqPlkYeUVOTgOBgT7H2AAF9XaAT6KstQIGNh4pHT7qwapj2V3ywOYpiLDqvdvsgmNzz4kEpjwU5w7PfsV0PXsZD0rT4w5GTTKS/5DoATB9YSjlBp7wTI6e9i6d+aqJZh3ApJNMXe5+lczjkLz88Ke9AddFPa2XLI7NVk3qzWdiLGAN3lnj7YxvG11f2mfj5CSmO7m+TaE64pFyay27QYsuRCGVyOqesgbTklcwVKXUsOJMcywUUnb79zrxhI2SuxJ2IO5ur8TUl+uY0qev9s6LMz6vGvuheCuJarBRvnQU4gZEAReenLhf/FcZTMPXNfl1odBBqUJn00V2TlAO2aIdLM2mgoJwr3RMq8m2OXV4tp1FYiM0VHE82b0TYvInAuyuF7NYnXLd3B9nGivzS8J3z/q916ZWL7Nq1+R37btnNnzw8 OOJopZUo MToZAhT5stxrzrl9vGo48eCBLzw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: "Arnd Bergmann" writes: > On Thu, Jan 9, 2025, at 17:18, Eric W. Biederman wrote: >> John Paul Adrian Glaubitz writes: >>> On Thu, 2025-01-09 at 09:56 +0100, Arnd Bergmann wrote: >>>> On Thu, Jan 9, 2025, at 09:46, John Paul Adrian Glaubitz wrote: >>>> > On Thu, 2025-01-09 at 09:43 +0100, Arnd Bergmann wrote: >>>> > > On Thu, Jan 9, 2025, at 09:01, Arnd Bergmann wrote: >>>> > > > This looks wrong to me: since ADDR_LIMIT_32BIT is not part of >>>> > > > PER_MASK, executing a regular binary from a taso binary no longer >>>> > > > reverts back to the entire 64-bit address space. >>>> > > > >>>> > > > It seems that the behavior on most other architectures changed in 2012 >>>> > > > commit 16f3e95b3209 ("cross-arch: don't corrupt personality flags upon >>>> > > > exec()"). >>>> > > > >>>> > >>>> > So, if I understand this correctly, we should just use PER_MASK on alpha >>>> > for 64-bit executables and allow the bits to be cleared for 32-bit binaries? >>>> >>>> I think ideally the EF_ALPHA_32BIT handling should use TIF_32BIT >>>> as we do on other architectures, at that point the custom SET_PERSONALITY() >>>> can be removed in favor of the asm-generic version. >>> >>> I have thought about that as well but I wasn't sure whether the extra >>> mangling on alpha was necessary. >>> >>>> Alternatively this could do something like the arm32 version (note >>>> that on arm, PER_LINUX_32BIT/ADDR_LIMIT_32BIT means "allow using >>>> the entire 32-bit address space rather than limiting to 26 bits for >>>> compatibility", while on alpha it means "use only 31 instead of >>>> 42 bits for addressing", but the logic can be the same): >>>> >>>> unsigned int personality = current->personality & ~PER_MASK; >>>> /* >>>> * APCS-26 is only valid for OABI executables >>>> */ >>>> if ((eflags & EF_ARM_EABI_MASK) == EF_ARM_EABI_UNKNOWN && >>>> (eflags & EF_ARM_APCS_26)) >>>> personality &= ~ADDR_LIMIT_32BIT; >>>> else >>>> personality |= ADDR_LIMIT_32BIT; >>>> set_personality(personality); >>> >>> So, this would be the 100% correct for alpha then which would not loose >>> any functionality even for 32-bit binaries? >> >> I don't think it is correct to think about 32-bit binaries on alpha. >> >> Alpha never had a 32bit instruction set. But at some point it looks >> like binaries that could not handle more than 31 bits of address >> space got ported and someone implemented a work-around. I guess this >> is the --taso option that Arnd mentioned. > > There was a well-documented use case for taso with emulation for > OSF/1 a.out binaries, in particular Netscape used 32-bit pointers. > However, the a.out support got removed a while back, and I have > not figured out why it was ever added for ELF. Maybe it was just > easy to duplicate this from the a.out loader? It looks too well done to be just a duplication from the a.out loader. Possibly OSF/1 was duplicating it from their a.out loader. > Obviously some 30 years ago it was common that software was > broken on 64-bit because of invalid integer-pointer casting, > but these days, it's much more common to be broken on 32-bit > instead. Agreed. >> I think the alpha version would look like: >> >> #define SET_PERSONALITY(ex) \ >> do { \ >> unsigned long personality = current->personality & ~PER_MASK; \ >> if ((EX).e_flags & EF_ALPHA_32BIT) \ >> personality |= ADDR_LIMIT_32BIT; \ >> else \ >> personality &= ~ADDR_LIMIT_32BIT \ >> set_personality(personality); \ >> while (0) > > Yes, that was what I was suggesting. > >> I do see code under arch/alpha/ testing ADDR_LIMIT_32BIT when >> setting STACK_TOP, TASK_UNMAPPED_BASE, and arch_get_unmapped_area. >> So I think the code still works. > > MIPS introduced the SET_PERSONALITY2() macro specifically to > allow the TIF flags to be set early enough to apply to the > stack allocation, so I suspect it only works partially. If you are in the personality flag you don't have the concern about things being set early enough. So I don't see anything that screams this code is broken. On the flip side if no one can think of any binaries that have that EF_ALPHA_32BIT set in e_flags, it is totally reasonable to remove the support from alpha and just have arch_check_elf fail (loudly) if such a binary is encountered. Then if someone cares the code can be added back in. Just removing the code is probably the easiest thing to do for long term maintenance. As then we are just maintaining the code people are using. Eric