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=-10.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 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 47D57C4338F for ; Mon, 2 Aug 2021 16:56:26 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 072B5600CD for ; Mon, 2 Aug 2021 16:56:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 072B5600CD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=FKtp42UT8SFnUADmnByAxSpwnzTFo9eip0SJ4R3P4vY=; b=wrP2ejSdYaDZy1 G3tttISo/NTxxvmOx3svEhEnm2Um9RQ5F43Ckm57Fp43R1Bf7RGMK5IqAaz2SY/kEdXkzkkfWg8y+ Bz1+OQbk4J4ARPZCwb6t7Imi4Gg4Wy6lqSX3zXwuUDlqgLOzSp+gvST4Y6TstmzSklnlOwz1tlPF/ p/MCYPa3OmXNmGj2YfVAnfN34AD8kOMH46VK8aykKz02+c51cKXduP370zgkYQl8JE9eoXe50VpG0 Ip8q5ipzXN154QUMZWB/prPpmNhLr6pziaFtPKudGz7CIOO+1kjAEZ2N+0Ht+wJ1x7DMQhyW5kjpD huaX7nLLWMZ/YDc7N1yw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mAbCx-00HFgO-NY; Mon, 02 Aug 2021 16:54:32 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mAbCs-00HFf6-VM for linux-arm-kernel@lists.infradead.org; Mon, 02 Aug 2021 16:54:28 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id BFC006112D; Mon, 2 Aug 2021 16:54:25 +0000 (UTC) Date: Mon, 2 Aug 2021 17:54:23 +0100 From: Catalin Marinas To: Mark Rutland Cc: linux-arm-kernel@lists.infradead.org, weiyuchen3@huawei.com, will@kernel.org, zhe.he@windriver.com Subject: Re: [PATCH] arm64: fix compat syscall return truncation Message-ID: <20210802165422.GM18685@arm.com> References: <20210802104200.21390-1-mark.rutland@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210802104200.21390-1-mark.rutland@arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210802_095427_056292_C45DCF1E X-CRM114-Status: GOOD ( 22.05 ) 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 Mon, Aug 02, 2021 at 11:42:00AM +0100, Mark Rutland wrote: > Due to inconsistencies in the way we manipulate compat GPRs, we have a > few issues today: > > * For audit and tracing, where error codes are handled as a (native) > long, negative error codes are expected to be sign-extended to the > native 64-bits, or they may fail to be matched correctly. Thus a > syscall which fails with an error may erroneously be identified as > failing. > > * For ptrace, *all* compat return values should be sign-extended for > consistency with 32-bit arm, but we currently only do this for > negative return codes. > > * As we may transiently set the upper 32 bits of some compat GPRs while > in the kernel, these can be sampled by perf, which is somewhat > confusing. This means that where a syscall returns a pointer above 2G, > this will be sign-extended, but will not be mistaken for an error as > error codes are constrained to the inclusive range [-4096, -1] where > no user pointer can exists. > > To fix all of these, we must consistently use helpers to get/set the > compat GPRs, ensuring that we never write the upper 32 bits of the > return code, and always sign-extend when reading the return code. This > patch does so, with the following changes: > > * We re-organise syscall_get_return_value() to always sign-extend for > compat tasks, and reimplement syscall_get_error() atop. We update > syscall_trace_exit() to use syscall_get_return_value(). > > * We consistently use syscall_set_return_value() to set the return > value, ensureing the upper 32 bits are never set unexpectedly. > > * As the core audit code currently uses regs_return_value() rather than > syscall_get_return_value(), we special-case this for > compat_user_mode(regs) such that this will do the right thing. Going > forward, we should try to move the core audit code over to > syscall_get_return_value(). > > Signed-off-by: Mark Rutland > Reported-by: He Zhe > Reported-by: weiyuchen > Cc: Catalin Marinas > Cc: Will Deacon Reviewed-by: Catalin Marinas (to the best of my knowledge, I can't guarantee all cases have been covered) _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel