Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp4705352pxb; Tue, 28 Sep 2021 02:06:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNN7ScVUed0Kv1Rio66kn516taD/Bc+8DY5nVRtsHkX6Mgzg0VbGa8HMZV0Pi/gr8/v9oB X-Received: by 2002:a17:906:4fd6:: with SMTP id i22mr5295846ejw.92.1632819985989; Tue, 28 Sep 2021 02:06:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632819985; cv=none; d=google.com; s=arc-20160816; b=cishJn4SNg0Ge0Rw9ZzgMMvDupuVVBroSw4Btoms+FYrtvvHT6vB9RZ2ajX5jTUPBd t8+Hut/Q2LWiFlbd4tnfNPDn9+QuINoW3luvBIkdAangYWIlXlM7YCRVckZs1X6dWiAK Kl1f5/g/o8stFxXkzRuPZdmzCKB5ytfA3CEaMFK7D56epkrIOryDwbYzAf+l8uIjKFCB MFSiwGlkBKZpNup0JoOQGVeQAB2WPcYHjENjYkmq2WBEcA7ulpU43MSA3mDR1CMQG6aB RZq0f5oeCof75fR7HRb6b/JeW0X4SxT4P4LOM50DeMZzaHoEHzfNN9ZrRPM74ipCx9RS R6FA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:in-reply-to :reply-to:subject:cc:to:from:user-agent:references:dkim-signature :dkim-signature; bh=7rw75VSmRwP8/RIgXFPLCmhyy1FPhry8ZvpaNKqg7aQ=; b=cMZke2YYpDNxX5nRCo9hQgnYrGsNz5sRf7lR4bYge9wtYspGaqwDkkpsJ53lN6oCKJ XHbjH4JPhU6x2et4F4ahWnR3yPm3nTQHjwOq5TaC4Uj2EziOdRiYwyjjytQ/oBM1j/Rz F7NWeg2kftyuEi3rabWqD5HR04bk4Sn8XpBBcsWC0s8VhxRn4NUwN5711kVVOEPjdaoU dcdYb+FoDKjJ1pUZ8racxBlFraaxezWHTFM9zhPa7tLuUqWvTOONeOBSpMsifc1NyJWP /UkdskSaPPovDJTf+VP5oUvHIlmsEP9+F3wSB4sa8dwkKttGwdKMssJHWSnuM6c1F5r1 aYDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=pWvl8r9N; dkim=neutral (no key) header.i=@suse.de; 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=suse.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 18si20520741ejj.268.2021.09.28.02.06.01; Tue, 28 Sep 2021 02:06:25 -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.de header.s=susede2_rsa header.b=pWvl8r9N; dkim=neutral (no key) header.i=@suse.de; 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=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239793AbhI1JEV (ORCPT + 99 others); Tue, 28 Sep 2021 05:04:21 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:55570 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239761AbhI1JEU (ORCPT ); Tue, 28 Sep 2021 05:04:20 -0400 Received: from relay1.suse.de (relay1.suse.de [149.44.160.133]) by smtp-out1.suse.de (Postfix) with ESMTP id 7AED721BC2; Tue, 28 Sep 2021 09:02:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1632819760; h=from:from:reply-to:reply-to:date:date:message-id:message-id:to:to: cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=7rw75VSmRwP8/RIgXFPLCmhyy1FPhry8ZvpaNKqg7aQ=; b=pWvl8r9N6tqQ508IhwJ0P2cgH9bILyurruAKGvqHocV6+0dOcAvYlz07rCporIsasrs+N7 f6gzMo0Akcn8ARvdw97rF1N2i9IRpCLOa4YTLu60KNiE0rakTzyY4Q3lPVsmO1pF5nJ0Za JFzZ8m/DDx4trXvdRqUjnAE679OOhJk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1632819760; h=from:from:reply-to:reply-to:date:date:message-id:message-id:to:to: cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=7rw75VSmRwP8/RIgXFPLCmhyy1FPhry8ZvpaNKqg7aQ=; b=OV+rtC16fdoMmYxtaeEUVcBdefcxrTBtLO7r1A83cfYnwlIZ3Xaubkr77qI9b1SNYp11Qx fybX1Zl3tv+JhmDg== Received: from g78 (unknown [10.163.24.38]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay1.suse.de (Postfix) with ESMTPS id 92F8725D50; Tue, 28 Sep 2021 09:02:37 +0000 (UTC) References: <20210927161955.28494-1-rpalethorpe@suse.com> User-agent: mu4e 1.4.15; emacs 27.2 From: Richard Palethorpe To: Arnd Bergmann Cc: the arch/x86 maintainers , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , linux-s390 , Linux Kernel Mailing List , Linux API , rpalethorpe@richiejp.com, Dominik Brodowski , LTP List Subject: Re: [PATCH] x86/entry/ia32: Ensure s32 is sign extended to s64 Reply-To: rpalethorpe@suse.de In-reply-to: Date: Tue, 28 Sep 2021 10:02:32 +0100 Message-ID: <87pmstf4yf.fsf@suse.de> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Arnd, Arnd Bergmann writes: > On Mon, Sep 27, 2021 at 6:21 PM Richard Palethorpe wrote: >> >> 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 > > Looks good to me, thanks for following through with this part, and for > checking the other syscalls! > > Reviewed-by: Arnd Bergmann Thanks for the feedback and suggestions. > > I've added this to my randconfig build tree as well, to see if > it causes any unexpected compile-time issues, though I > don't expect any problems here. > > There are a few things that I think we should do as a follow-up: > > - do the same thing in the generic syscall wrapper, to ensure the > other architectures also do the sign-extension. > > - Fix the big-endian architectures (ppc64be, mips64be, sparc, s390 > parisc) so they pass the correct signal mask, either using your original > approach, or by reworking the syscall to detect compat syscalls > at runtime, killing off the separate entry point > > - Go through the compat syscalls to see if any of them can be > removed once all architectures do sign-extension correctly. > > Are you motivated to help out with one or more of these as well? > > Arnd I am motivated. There have been a number of nasty bugs in compat code. Including high-profile stuff like CVE-2021-22555. However also just relatively minor things which cause tests to fail and could be masking worse issues. I like the idea of removing as much syscall/arch specific compat code as possible. I also wonder whether syscalls like ftruncate64 can be generalised and if there would be any benefit to doing so. All it is doing is merging two u32 args into an s64 arg. -- Thank you, Richard.