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=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT 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 94651C10F29 for ; Tue, 17 Mar 2020 12:24:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 70E342076D for ; Tue, 17 Mar 2020 12:24:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727347AbgCQMYE (ORCPT ); Tue, 17 Mar 2020 08:24:04 -0400 Received: from foss.arm.com ([217.140.110.172]:37060 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726452AbgCQMXt (ORCPT ); Tue, 17 Mar 2020 08:23:49 -0400 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 71C0C101E; Tue, 17 Mar 2020 05:23:49 -0700 (PDT) Received: from e119884-lin.cambridge.arm.com (e119884-lin.cambridge.arm.com [10.1.196.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6157C3F534; Tue, 17 Mar 2020 05:23:46 -0700 (PDT) From: Vincenzo Frascino To: linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com, linux-mips@vger.kernel.org, x86@kernel.org Cc: Vincenzo Frascino , Catalin Marinas , Will Deacon , Arnd Bergmann , Russell King , Paul Burton , Thomas Gleixner , Andy Lutomirski , Ingo Molnar , Borislav Petkov , Stephen Boyd , Mark Salyzyn , Kees Cook , Peter Collingbourne , Dmitry Safonov <0x7f454c46@gmail.com>, Andrei Vagin , Nick Desaulniers , Marc Zyngier , Mark Rutland , Will Deacon Subject: [PATCH v4 18/26] arm64: vdso32: Replace TASK_SIZE_32 check in vgettimeofday Date: Tue, 17 Mar 2020 12:22:12 +0000 Message-Id: <20200317122220.30393-19-vincenzo.frascino@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200317122220.30393-1-vincenzo.frascino@arm.com> References: <20200317122220.30393-1-vincenzo.frascino@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For ABI compatibility with arm32, the compat vDSO layer on arm64 needs to return -EINVAL when UINTPTR_MAX is passed as argument to the clock_get* functions. Replace TASK_SIZE_32 with a more semantically correct formula that checks for wrapping around 0. Note: This will allow to not define TASK_SIZE_32 for the vdso headers in a future patch that will introduce asm/vdso/processor.h on arm64. Cc: Catalin Marinas Cc: Will Deacon Signed-off-by: Vincenzo Frascino --- arch/arm64/kernel/vdso32/vgettimeofday.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kernel/vdso32/vgettimeofday.c b/arch/arm64/kernel/vdso32/vgettimeofday.c index 54fc1c2ce93f..91138077b073 100644 --- a/arch/arm64/kernel/vdso32/vgettimeofday.c +++ b/arch/arm64/kernel/vdso32/vgettimeofday.c @@ -8,11 +8,14 @@ #include #include +#define VALID_CLOCK_ID(x) \ + ((x >= 0) && (x < VDSO_BASES)) + int __vdso_clock_gettime(clockid_t clock, struct old_timespec32 *ts) { /* The checks below are required for ABI consistency with arm */ - if ((u32)ts >= TASK_SIZE_32) + if ((u32)ts > UINTPTR_MAX - sizeof(*ts) + 1) return -EFAULT; return __cvdso_clock_gettime32(clock, ts); @@ -22,7 +25,7 @@ int __vdso_clock_gettime64(clockid_t clock, struct __kernel_timespec *ts) { /* The checks below are required for ABI consistency with arm */ - if ((u32)ts >= TASK_SIZE_32) + if ((u32)ts > UINTPTR_MAX - sizeof(*ts) + 1) return -EFAULT; return __cvdso_clock_gettime(clock, ts); @@ -38,9 +41,12 @@ int __vdso_clock_getres(clockid_t clock_id, struct old_timespec32 *res) { /* The checks below are required for ABI consistency with arm */ - if ((u32)res >= TASK_SIZE_32) + if ((u32)res > UINTPTR_MAX - sizeof(res) + 1) return -EFAULT; + if (!VALID_CLOCK_ID(clock_id) && res == NULL) + return -EINVAL; + return __cvdso_clock_getres_time32(clock_id, res); } -- 2.25.1 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=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 51D62C10F29 for ; Tue, 17 Mar 2020 12:28:09 +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 1E85220768 for ; Tue, 17 Mar 2020 12:28:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="aB232VKV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1E85220768 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-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=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=4AeIdqkrLbJoDhq8Zjt/f5QK8PwC0S54ruWdyOQc24c=; b=aB232VKVJ1hQGp 0F0vhsIwRahHAwwaNGjx4a93hiGHIVS5motOfyQo41TDzLUOljXgMQvj+uQAspn5aEx53fqq3agV8 swbsZ4T6NnzXUXbrueI2hv6NEald8n2DBy1tc9ikJ1LBCy7c/zsCK9QEI2E8rDvwPlZyDZwny9I4q eM7ubvlfc4IfEquhgjn8P18hvRH7EAYrTLlpkDB8bBH/aJnwYjjgtZj0iUPthh2N+nFDEKO2PJ8C3 I2djavwt/V8S+D976KtNFfmj4U2lTWzODnw5E8B3idd/JBT13cecl1YLtdAa5mpxSPQxwnSqcpCpw Ghm4k2JT7q6d9uXHcCdw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jEBKG-0003QX-Gj; Tue, 17 Mar 2020 12:28:04 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jEBGA-0006Ic-CS for linux-arm-kernel@lists.infradead.org; Tue, 17 Mar 2020 12:23:52 +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 71C0C101E; Tue, 17 Mar 2020 05:23:49 -0700 (PDT) Received: from e119884-lin.cambridge.arm.com (e119884-lin.cambridge.arm.com [10.1.196.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6157C3F534; Tue, 17 Mar 2020 05:23:46 -0700 (PDT) From: Vincenzo Frascino To: linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com, linux-mips@vger.kernel.org, x86@kernel.org Subject: [PATCH v4 18/26] arm64: vdso32: Replace TASK_SIZE_32 check in vgettimeofday Date: Tue, 17 Mar 2020 12:22:12 +0000 Message-Id: <20200317122220.30393-19-vincenzo.frascino@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200317122220.30393-1-vincenzo.frascino@arm.com> References: <20200317122220.30393-1-vincenzo.frascino@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200317_052350_530541_2C1BFB71 X-CRM114-Status: GOOD ( 12.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Nick Desaulniers , Dmitry Safonov <0x7f454c46@gmail.com>, Kees Cook , Arnd Bergmann , Stephen Boyd , Catalin Marinas , Will Deacon , Russell King , Mark Salyzyn , Paul Burton , Ingo Molnar , Borislav Petkov , Andy Lutomirski , Marc Zyngier , Will Deacon , Thomas Gleixner , Vincenzo Frascino , Peter Collingbourne , Andrei Vagin Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org For ABI compatibility with arm32, the compat vDSO layer on arm64 needs to return -EINVAL when UINTPTR_MAX is passed as argument to the clock_get* functions. Replace TASK_SIZE_32 with a more semantically correct formula that checks for wrapping around 0. Note: This will allow to not define TASK_SIZE_32 for the vdso headers in a future patch that will introduce asm/vdso/processor.h on arm64. Cc: Catalin Marinas Cc: Will Deacon Signed-off-by: Vincenzo Frascino --- arch/arm64/kernel/vdso32/vgettimeofday.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kernel/vdso32/vgettimeofday.c b/arch/arm64/kernel/vdso32/vgettimeofday.c index 54fc1c2ce93f..91138077b073 100644 --- a/arch/arm64/kernel/vdso32/vgettimeofday.c +++ b/arch/arm64/kernel/vdso32/vgettimeofday.c @@ -8,11 +8,14 @@ #include #include +#define VALID_CLOCK_ID(x) \ + ((x >= 0) && (x < VDSO_BASES)) + int __vdso_clock_gettime(clockid_t clock, struct old_timespec32 *ts) { /* The checks below are required for ABI consistency with arm */ - if ((u32)ts >= TASK_SIZE_32) + if ((u32)ts > UINTPTR_MAX - sizeof(*ts) + 1) return -EFAULT; return __cvdso_clock_gettime32(clock, ts); @@ -22,7 +25,7 @@ int __vdso_clock_gettime64(clockid_t clock, struct __kernel_timespec *ts) { /* The checks below are required for ABI consistency with arm */ - if ((u32)ts >= TASK_SIZE_32) + if ((u32)ts > UINTPTR_MAX - sizeof(*ts) + 1) return -EFAULT; return __cvdso_clock_gettime(clock, ts); @@ -38,9 +41,12 @@ int __vdso_clock_getres(clockid_t clock_id, struct old_timespec32 *res) { /* The checks below are required for ABI consistency with arm */ - if ((u32)res >= TASK_SIZE_32) + if ((u32)res > UINTPTR_MAX - sizeof(res) + 1) return -EFAULT; + if (!VALID_CLOCK_ID(clock_id) && res == NULL) + return -EINVAL; + return __cvdso_clock_getres_time32(clock_id, res); } -- 2.25.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel