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=-13.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, 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 8461FC433ED for ; Thu, 22 Apr 2021 16:57:44 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 11A0C6142F for ; Thu, 22 Apr 2021 16:57:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 11A0C6142F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=j43p5O3i1ZNXwoEEKzEAZC0PzZxkL63LTSpnEamtohc=; b=RfZs9rYH/wCXyUF3GNEV/feKT DbeEC5BsG2JGrRn9kcF+wLWdXxXn444k5ArniTn1GFC4Ki9g8jVbQOAqZingUB8dkxESjwnu8NShC hl7qfNUiJKTMBTwm8f3MaBjR9e0y9wM5oIL6rZrptMi1oDRvNDWkJNp6RIMJhgLcR6q4xxVvrnfrh oxvwKp0fsxfPcCBoUQfgKBJYEbyIiwkc6QdpUOknKJsz+vRHtw2xd+i6nvl1EHTroO93n2U9jrWbI ffmq67eVCQHMV6u2dlksVxPe1/YmE26PxZcanAbNGRMm3f5z4bGGvt9xHacUWfeGT6leX1qDeEi2e Zj9d25FpA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lZccO-00H8sE-3x; Thu, 22 Apr 2021 16:55:56 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lZccK-00H8rr-VK for linux-arm-kernel@desiato.infradead.org; Thu, 22 Apr 2021 16:55:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=2/xhyW4ngMkvNKiQYmSP3vtDbn0yh9J8uNr9azyb+wo=; b=PvGKIUy/pnfdikaDINvqkepzAf eTV++CiTsNFyUw/4WSiPMKAi5JZ5cgmWHoefz6c//FGKdH/tvLO7UP4Iz7roNWEHKkO5kWVSuJoZh SrjoisY4doEbrofVtLzqUBQl6DtyW5/37rn33LbsBhHdXwBrECRl+en1a8yYs6OVX5YXnKczniCMe Mm1fcqsbI/VOU4Az+YmWKF1mzJ2Ik1YkK7rw8XUUrHYf/4Iw7Lt1PyzBAkKtuswfZoHyfiiAew21l tS0Fvnlj793dfyusAlkp1mRWdSoX5nBD+snzWqpeXMp4hgG5UmTO90c0lzEXs4bHPaZQE0kUV+uBe lHcYkkIQ==; Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lZccI-00Drf8-18 for linux-arm-kernel@lists.infradead.org; Thu, 22 Apr 2021 16:55:51 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 076B311D4; Thu, 22 Apr 2021 09:55:49 -0700 (PDT) Received: from C02TD0UTHF1T.local (unknown [10.57.22.241]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 73A843F694; Thu, 22 Apr 2021 09:55:47 -0700 (PDT) Date: Thu, 22 Apr 2021 17:55:45 +0100 From: Mark Rutland To: He Zhe Cc: oleg@redhat.com, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, paul@paul-moore.com, eparis@redhat.com, linux-audit@redhat.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/3] arm64: syscall.h: Add sign extension handling in syscall_get_return_value for compat Message-ID: <20210422165545.GE66392@C02TD0UTHF1T.local> References: <20210416075533.7720-1-zhe.he@windriver.com> <20210416075533.7720-2-zhe.he@windriver.com> <20210421174105.GB52940@C02TD0UTHF1T.local> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210421174105.GB52940@C02TD0UTHF1T.local> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210422_095550_140248_E41F1227 X-CRM114-Status: GOOD ( 22.69 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Apr 21, 2021 at 06:41:05PM +0100, Mark Rutland wrote: > On Fri, Apr 16, 2021 at 03:55:32PM +0800, He Zhe wrote: > > Add sign extension handling in syscall_get_return_value so that it can > > handle 32-bit compatible case and can be used by for example audit, just > > like what syscall_get_error does. > > If a compat syscall can ever legitimately return a non-error value with > bit 31 set, and this sign-extends it, is that ever going to reach > userspace as a 64-bit value? > > IIUC things like mmap() can return pointers above 2GiB for a compat > task, so I'm a bit uneasy that we'd handle those wrong. I can't see a > way of preventing that unless we keep the upper 32 bits for errors. Looking at this with fresh eyes, I think we can more closely mirror syscall_get_error(), and do something like: static inline long syscall_get_return_value(struct task_struct *task, struct pt_regs *regs) { long val = regs->regs[0]; long error = val; if (is_compat_thread(task_thread_info(task))) error = sign_extend64(error, 31); return IS_ERR_VALUE(error) ? error : val; } Thanks, Mark. > > Mark. > > > > > Signed-off-by: He Zhe > > --- > > arch/arm64/include/asm/syscall.h | 7 ++++++- > > 1 file changed, 6 insertions(+), 1 deletion(-) > > > > diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h > > index cfc0672013f6..cd7a22787aeb 100644 > > --- a/arch/arm64/include/asm/syscall.h > > +++ b/arch/arm64/include/asm/syscall.h > > @@ -44,7 +44,12 @@ static inline long syscall_get_error(struct task_struct *task, > > static inline long syscall_get_return_value(struct task_struct *task, > > struct pt_regs *regs) > > { > > - return regs->regs[0]; > > + long val = regs->regs[0]; > > + > > + if (is_compat_thread(task_thread_info(task))) > > + val = sign_extend64(val, 31); > > + > > + return val; > > } > > > > static inline void syscall_set_return_value(struct task_struct *task, > > -- > > 2.17.1 > > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel