From patchwork Thu May 12 11:26:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 9079471 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E0BA49F1C3 for ; Thu, 12 May 2016 11:29:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0E2BD200C1 for ; Thu, 12 May 2016 11:29:13 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3052E20212 for ; Thu, 12 May 2016 11:29:12 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1b0omS-0003ne-1R; Thu, 12 May 2016 11:27:48 +0000 Received: from mail-bl2on0066.outbound.protection.outlook.com ([65.55.169.66] helo=na01-bl2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b0omL-0003EH-GB for linux-arm-kernel@lists.infradead.org; Thu, 12 May 2016 11:27:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-caviumnetworks-com; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=qxLnKJnnI8Tuf8H4+NLDW7FskIBtEbSObLWQ3ylSBcc=; b=X5nz+3mDtlzu2jgWVUxEwuxlalhtdo6TvUm2FPrgWoxE70lWXncdqaUR1B1YekD4Mhc+MZ3fFEDcD/XlFwgJt+NfET9jZX2HfOzA7ndxh3WRVA8/zMXt+RGYKxvIr8FOpWFdGrKKJOHO5tm9Z37naueHoHnShQvRrYGveYxkKGc= Authentication-Results: arndb.de; dkim=none (message not signed) header.d=none;arndb.de; dmarc=none action=none header.from=caviumnetworks.com; Received: from localhost (95.143.213.121) by BN4PR07MB2226.namprd07.prod.outlook.com (10.164.63.144) with Microsoft SMTP Server (TLS) id 15.1.492.11; Thu, 12 May 2016 11:27:18 +0000 From: Yury Norov To: , Subject: [PATCH] arm64: fix current_thread_info()->addr_limit setup Date: Thu, 12 May 2016 14:26:54 +0300 Message-ID: <1463052414-29033-1-git-send-email-ynorov@caviumnetworks.com> X-Mailer: git-send-email 2.5.0 MIME-Version: 1.0 X-Originating-IP: [95.143.213.121] X-ClientProxiedBy: AM2PR03CA0017.eurprd03.prod.outlook.com (10.160.207.27) To BN4PR07MB2226.namprd07.prod.outlook.com (10.164.63.144) X-MS-Office365-Filtering-Correlation-Id: dd9715a8-2b7c-4140-fd0e-08d37a5860b9 X-Microsoft-Exchange-Diagnostics: 1; BN4PR07MB2226; 2:A6q6BoAXdaaIKAFfFSP+dM3SG0PCPDiGVCOwOunxRvrR4js3YNSfY8ahQKo8MA7XeJXzAMSXeUgKdppxY5fMhEMtLHfdocOj9ZlWpm2VrRxvBKbag/4dKhQ2tzjqTw8Ykq0dlhfpYgarVL6V0aQr3mAD1wk/YsYGFQCI1WhBah/eiVxT+d3NHX+wGucWTmaK; 3:43LWSv3xXCR+yz9Wl0asX5649yvwGwTzBS1vLNUsbbqjZEAAnCk9e5hVDT2MCbp1v0wWUQOiR9PIw5Uj2i8hpF8NIXpyOC5mlNuh949G2E3rjg2GzZP4FVnUPKW/FqCd X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN4PR07MB2226; X-Microsoft-Exchange-Diagnostics: 1; BN4PR07MB2226; 25:X9pLNaYrSQj0pe/qgFAY0Dp8Qaz54qzvypL60I+LuB77wl8mcgJUL07xzj8s86Mu2/pS3n+JEvuar3L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IISvfK8RgXjOEBalxWvfpASt6X4WIZqK3dwii7qY1yi1L3lTKOW87FiUu/xLMLyvP1cKoamuMN9CVwFwgSeHkxmjwCDgjPJv2NYRxdziC3ACczw7F97Mm662+Cidz61NG1rzwwgDKbhB/kDqjbwOUn7P1t/zTpfr9MHSScuBqGilUY2dDYDt4P5fYB5n1RgFis3yz2PHKmuYOqpD1wrqbPqVPksaGuSXX5xO6QqlgWgQXu6XjgiDSn8Yi/u8twb79ynKBjsQBTAmbnEwVdOnShNsKCPxMRpoSSgrGzgjH7rOkgFtDXzCNv0ijAZHKYfs1bc9fjSQY5a+XNcuatH2IvNZY8B1POQNSYokqRZifOQ9xe3f/wCI= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001); SRVR:BN4PR07MB2226; BCL:0; PCL:0; RULEID:; SRVR:BN4PR07MB2226; X-Microsoft-Exchange-Diagnostics: 1; BN4PR07MB2226; 4:kjGdFu/YD3/s4YM21a47n+dqIibED7adt8DBnv2uuyIqnkbk3O6x5bmHIiaGR+cbaV02LvlhgD/xSgXXwa4DG/blXwAReBMM7OTb9eAG+f+9KufSzX07DGJ2AD53y3PE/F4NGIaRkD2jEopkcfnsRtzu8qM5lYy+LcdjePWEn+H51BeVqqh4j8cYqzM+q6ZBcU3eJFVBuMJKMxdEyOo6MVkoYnvFERTgXhE9phAM0cBa9EQ0Y8ZEbuQMi8+a7kx7SO7/mT4ACblxxZt94zDlxn7scw5xF7p5QGIo/CynSbnaYyM2L7bqO5VG3Z8pB7mAM0dUME2CP3A6tOoMC3wK9+INYXrktOIfnN7txPg8GWowPcZifNeYX/gfgqu7bePx X-Forefront-PRVS: 0940A19703 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6069001)(76506005)(47776003)(36756003)(48376002)(229853001)(107886002)(6116002)(3846002)(42186005)(50466002)(586003)(50226002)(5001770100001)(5008740100001)(5003940100001)(66066001)(4001430100002)(33646002)(92566002)(81166006)(189998001)(77096005)(50986999)(15975445007)(5004730100002)(19580395003)(19580405001)(2906002); DIR:OUT; SFP:1101; SCL:1; SRVR:BN4PR07MB2226; H:localhost; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN4PR07MB2226; 23:yoW9r46sWqzQvCCChIrpMEHtbiDWOAg1FUodcEzq1FZJeFuHM2INPtV2ym3sA/o+j0OaJx5WegWpEtKHTjofm91GaMYBzTvk2hLUwiBi1F1ilJdcfIq1e/+BgkktZ0/thXuSiTh6HOUhlkGZFAfugAhuUEVgVs3I1dteIRQNESLyqULKl+TW0NSFh5lJ7mjcjfFZ1oXOD65ak/HDcCQtyvvJp71/w0tixeYNmNzLAv4AuT/7BdtgHllDAM0lTr8xcsN8MXshOuMxA1aIWUuFO8V2zGJK16x5d3dafduQ/Y6IJm7J4o6TcDgvYwZFj/UyakC6Zmu2BQeDkX1RIinq0/6I9hwrERhARpGuyq5jzJskBXZ9Mo6AQWGGp/Otv/6tPYbWKZ4cHJLc+ZQkGXy1ab7HUq4HI0UUYziQu/c8qjKiX1UZ4oupsk+iH9vZx4oqlgC/3z5NK+2sMOhMcagDUtMZP6/9rJT8eR6Ty0Y5aWBqDK3cMrOicLB+DdeBeD7MIjkbKs6SKHM1Yd16Xtz/bVCAcYASW4NqyVcI2Fnkw1jvoNx/nzH0vyfBIzGbp9BveqwJoRuRUYmKsIDWgu4QOtLonCOrruQTZjsfHcU2weKcRy7hr7HdLcFudJqhn8eLGL25eQHEQd8ZztktgN6v+OZUtaoQ6XtS7pCxhhrj5QkUK1BczVPhAg8cv4rwtFQPW5bDXj7PZ7jDPSQTb/pwzpxRlK7z1GXbgNPtiSBZPM1+P4B7Sy25J1WyxR9SFZPQ0QyItwbDWzTbBA/YuQHvQTX+AxuAqUTgejky6kkpgHEIz6AuKFmCt1wiX1HDA3329UXBfwxagTAkZsmYLGLjJ6GafwGlT95gBkPN8DOnZ13eSIPpnAwkv/hcN6MvkSfiAjh2v09g3TPHEuHfcr7Nsg== X-Microsoft-Exchange-Diagnostics: 1; BN4PR07MB2226; 5:qaZaEWFy1ndAcu4kN7Xg3b8hjRJuXRoo+yIpwu9a0Db+1dbR+ZWYuLEawgP7xz5CuNNHCodp46KItxtrcgrrKlu1cWXOPy0qamzB2CMR1tk+dw+Xk7WKnuexP67bIR5B3um9No0cPMQ23qcuVjOHpQ==; 24:3qsZkmv2smrtIB52NQK+d1ScU5I3ltYSEodbu8SfTXak9JPZtHwywClfqEA/+5/MBmY8908dbQPRwlg5ZVJFmJPEnp5RHDjjw6j/dnasZBU=; 7:FOoT8f8LvD3VBf9vlCQpxQwE7QCPg3F3q15XtvPsYD8OqMQ/J2BZS3rGW6xglsBBvuhhypAcUenShAG6kiwIoWwelz1p/3aXm/pQi0h2XjOOxExlxgjtiWhmCvFUPZNqvxPYsVVsJF1aXxhsAzQxPGu58C29A6XSLLJriI8luw9hW/9EJsPJV7F4GKEVR5Ql SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 May 2016 11:27:18.4759 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN4PR07MB2226 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160512_042742_022207_FBDF73E6 X-CRM114-Status: UNSURE ( 7.69 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -1.9 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yury Norov , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP At elf loading in flush_old_exec() in fs/exec.c, generic code sets current_thread_info()->addr_limit to one that corresponds aarch64 value, and ignores compat mode there as corresponding status setup happens later on in load_elf_binary() by SET_PERSONALITY() macro. As result, compat task has wrong addr_limit, and it may cause various bugs. This patch fixes it. It also fixes USER_DS macro to return different values depending on compat at runtime. It was discovered during ilp32 development. See details here: https://lkml.org/lkml/2016/5/11/975 Signed-off-by: Yury Norov --- arch/arm64/include/asm/elf.h | 11 +++++++++-- arch/arm64/include/asm/uaccess.h | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h index 24ed037..fda75ce 100644 --- a/arch/arm64/include/asm/elf.h +++ b/arch/arm64/include/asm/elf.h @@ -138,7 +138,10 @@ typedef struct user_fpsimd_state elf_fpregset_t; */ #define ELF_PLAT_INIT(_r, load_addr) (_r)->regs[0] = 0 -#define SET_PERSONALITY(ex) clear_thread_flag(TIF_32BIT); +#define SET_PERSONALITY(ex) do { \ + clear_thread_flag(TIF_32BIT); \ + set_fs(TASK_SIZE_64); \ +} while (0) #define ARCH_DLINFO \ do { \ @@ -181,7 +184,11 @@ typedef compat_elf_greg_t compat_elf_gregset_t[COMPAT_ELF_NGREG]; ((x)->e_flags & EF_ARM_EABI_MASK)) #define compat_start_thread compat_start_thread -#define COMPAT_SET_PERSONALITY(ex) set_thread_flag(TIF_32BIT); +#define COMPAT_SET_PERSONALITY(ex) do { \ + set_thread_flag(TIF_32BIT); \ + set_fs(TASK_SIZE_32); \ +} while (0) + #define COMPAT_ARCH_DLINFO extern int aarch32_setup_vectors_page(struct linux_binprm *bprm, int uses_interp); diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index 0685d74..5b269e6 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -60,7 +60,7 @@ extern int fixup_exception(struct pt_regs *regs); #define KERNEL_DS (-1UL) #define get_ds() (KERNEL_DS) -#define USER_DS TASK_SIZE_64 +#define USER_DS TASK_SIZE #define get_fs() (current_thread_info()->addr_limit) static inline void set_fs(mm_segment_t fs)