Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp4100951pxb; Mon, 27 Sep 2021 09:24:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1qD7rW+n4C03Ij5RZl8hIhXDs//FnZs3buCrx9K9K9KwUKCjof6HAteKq1E34vEP06apM X-Received: by 2002:a62:15c3:0:b0:43d:e6be:156a with SMTP id 186-20020a6215c3000000b0043de6be156amr527120pfv.1.1632759852763; Mon, 27 Sep 2021 09:24:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632759852; cv=none; d=google.com; s=arc-20160816; b=VP75m0JOE5Mb2MEvuGpxLJqTnvlQILVC8cl4VnKZSRP01+sAjmL/2KgrqMwFixIBRg sSrVGY9+EwUWacE1Gu0TbDjvFz9bbUFAYXPVgWs90XW0SnJ5YuxWWmuw6soNNDgyW6cZ AeB/993SOABa5NybNjE2loVYuUI/JaF+HfiaaSdp0UwFKdOq5EOCu3EweT+zbxqjEFHI Dnulv6v30q6l4ODb8HB0f1VQnQZU0hJoaCKDdTAluP+nDVetbFOHkH6XzlKTCl7l0+Uz eZumNeWvzBVmwcJiR0M2TtKkx3ZV+242zwqKQ0GqMK/5jkqBfSXg36ZelwculHh6AaS8 ADEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=OhdVD9gOAiEfK7wpJLmapbTk6U8empUyrJJ+9sKjxDc=; b=AkacY7SttdsimgayNt2kQLjus2yBD9U4k6pTykJKjTwZV7qXl0R0b+qWV1H3VCpAnO n6eU5yRUZpvPMf5M1Zr0sjQhyLGmNmNxOZ6GR+uUjdsqTGqsK8BNU4RuYwjoOXdM4+jX nXuxkvNKayBH0ESrYm6b3Qr+zHwiY/74qLOosmYbEwPh+3LYuF/z3SPMhBZr30q8uNYQ Zmy5LMABSefYYXv6oI9MrWxbF3MUBKp5FTQBK1RwsC9T8pWMxxoVth5jOM94xBodZ/1s ZeVWrI/9FShCrkbauF3v5LypNeu48ucYAtFIu5mr2v8pTZz8XzUzRCu9DReWZojCHJXY jAJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b="UE0ndxT/"; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rm6si18163518pjb.86.2021.09.27.09.23.55; Mon, 27 Sep 2021 09:24:12 -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=@suse.com header.s=susede1 header.b="UE0ndxT/"; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235387AbhI0QWl (ORCPT + 99 others); Mon, 27 Sep 2021 12:22:41 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:39550 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235341AbhI0QWk (ORCPT ); Mon, 27 Sep 2021 12:22:40 -0400 Received: from relay1.suse.de (relay1.suse.de [149.44.160.133]) by smtp-out2.suse.de (Postfix) with ESMTP id B1E5520174; Mon, 27 Sep 2021 16:21:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1632759661; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=OhdVD9gOAiEfK7wpJLmapbTk6U8empUyrJJ+9sKjxDc=; b=UE0ndxT/7SMUQi2S12WiU1L8o3vezLNsivOroJUx3J6QMJZLqypB8enMbr/LXtEAwGfFAK NzJ4YnTh1xfRrxWsdPLZurdMg5t7WZFYMs4KALj0b0mNHEFMJXFyVTgeZZs4VR5x0dP06T Q0cDAVQEP9WHufbko8M+3o9EQbDZ9BY= Received: from g78.suse.de (unknown [10.163.24.38]) by relay1.suse.de (Postfix) with ESMTP id A3FD825D3E; Mon, 27 Sep 2021 16:20:58 +0000 (UTC) From: Richard Palethorpe To: x86@kernel.org Cc: Richard Palethorpe , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , rpalethorpe@richiejp.com, Dominik Brodowski , ltp@lists.linux.it Subject: [PATCH] x86/entry/ia32: Ensure s32 is sign extended to s64 Date: Mon, 27 Sep 2021 17:19:55 +0100 Message-Id: <20210927161955.28494-1-rpalethorpe@suse.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Presently ia32 registers stored in ptregs are unconditionally cast to unsigned int by the ia32 stub. They are then cast to long when passed to __se_sys*, but will not be sign extended. This takes the sign of the syscall argument into account in the ia32 stub. It still casts to unsigned int to avoid implementation specific behavior. However then casts to int or unsigned int as necessary. So that the following cast to long sign extends the value. This fixes the io_pgetevents02 LTP test when compiled with -m32. Presently the systemcall io_pgetevents_time64 unexpectedly accepts -1 for the maximum number of events. It doesn't appear other systemcalls with signed arguments are effected because they all have compat variants defined and wired up. A less general solution is to wire up the systemcall: https://lore.kernel.org/ltp/20210921130127.24131-1-rpalethorpe@suse.com/ Fixes: ebeb8c82ffaf ("syscalls/x86: Use 'struct pt_regs' based syscall calling for IA32_EMULATION and x32") Signed-off-by: Richard Palethorpe Suggested-by: Arnd Bergmann --- arch/s390/include/asm/syscall_wrapper.h | 2 -- arch/x86/include/asm/syscall_wrapper.h | 25 +++++++++++++++++++++---- include/linux/syscalls.h | 1 + 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/arch/s390/include/asm/syscall_wrapper.h b/arch/s390/include/asm/syscall_wrapper.h index ad2c996e7e93..25ab58b0ded1 100644 --- a/arch/s390/include/asm/syscall_wrapper.h +++ b/arch/s390/include/asm/syscall_wrapper.h @@ -7,8 +7,6 @@ #ifndef _ASM_S390_SYSCALL_WRAPPER_H #define _ASM_S390_SYSCALL_WRAPPER_H -#define __SC_TYPE(t, a) t - #define SYSCALL_PT_ARG6(regs, m, t1, t2, t3, t4, t5, t6)\ SYSCALL_PT_ARG5(regs, m, t1, t2, t3, t4, t5), \ m(t6, (regs->gprs[7])) diff --git a/arch/x86/include/asm/syscall_wrapper.h b/arch/x86/include/asm/syscall_wrapper.h index 6a2827d0681f..811139a82b13 100644 --- a/arch/x86/include/asm/syscall_wrapper.h +++ b/arch/x86/include/asm/syscall_wrapper.h @@ -58,12 +58,29 @@ extern long __ia32_sys_ni_syscall(const struct pt_regs *regs); ,,regs->di,,regs->si,,regs->dx \ ,,regs->r10,,regs->r8,,regs->r9) \ + +/* SYSCALL_PT_ARGS is Adapted from s390x */ +#define SYSCALL_PT_ARG6(m, t1, t2, t3, t4, t5, t6) \ + SYSCALL_PT_ARG5(m, t1, t2, t3, t4, t5), m(t6, (regs->bp)) +#define SYSCALL_PT_ARG5(m, t1, t2, t3, t4, t5) \ + SYSCALL_PT_ARG4(m, t1, t2, t3, t4), m(t5, (regs->di)) +#define SYSCALL_PT_ARG4(m, t1, t2, t3, t4) \ + SYSCALL_PT_ARG3(m, t1, t2, t3), m(t4, (regs->si)) +#define SYSCALL_PT_ARG3(m, t1, t2, t3) \ + SYSCALL_PT_ARG2(m, t1, t2), m(t3, (regs->dx)) +#define SYSCALL_PT_ARG2(m, t1, t2) \ + SYSCALL_PT_ARG1(m, t1), m(t2, (regs->cx)) +#define SYSCALL_PT_ARG1(m, t1) m(t1, (regs->bx)) +#define SYSCALL_PT_ARGS(x, ...) SYSCALL_PT_ARG##x(__VA_ARGS__) + +#define __SC_COMPAT_CAST(t, a) \ + (__typeof(__builtin_choose_expr(__TYPE_IS_L(t), 0, 0U))) \ + (unsigned int)a + /* Mapping of registers to parameters for syscalls on i386 */ #define SC_IA32_REGS_TO_ARGS(x, ...) \ - __MAP(x,__SC_ARGS \ - ,,(unsigned int)regs->bx,,(unsigned int)regs->cx \ - ,,(unsigned int)regs->dx,,(unsigned int)regs->si \ - ,,(unsigned int)regs->di,,(unsigned int)regs->bp) + SYSCALL_PT_ARGS(x, __SC_COMPAT_CAST, \ + __MAP(x, __SC_TYPE, __VA_ARGS__)) \ #define __SYS_STUB0(abi, name) \ long __##abi##_##name(const struct pt_regs *regs); \ diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index 69c9a7010081..a492276a11f1 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -122,6 +122,7 @@ enum landlock_rule_type; #define __TYPE_IS_LL(t) (__TYPE_AS(t, 0LL) || __TYPE_AS(t, 0ULL)) #define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a #define __SC_CAST(t, a) (__force t) a +#define __SC_TYPE(t, a) t #define __SC_ARGS(t, a) a #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long)) -- 2.31.1