From patchwork Wed Sep 5 14:34:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 146003 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp5014876ljw; Wed, 5 Sep 2018 07:34:49 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaCtoqQbQnk18X/hZc57S1iHymzq9OqTYzp4lCgPCKOzfCas4Kj9RSjTgVAbl7rKi9plKkj X-Received: by 2002:a63:4506:: with SMTP id s6-v6mr432631pga.422.1536158088989; Wed, 05 Sep 2018 07:34:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536158088; cv=none; d=google.com; s=arc-20160816; b=IpE3ibMjTt1L2KUjYiZgtdCZk0vFDDBY4fYUAS82MaYjCqMZHminiE+oG0/emYilWw fhRAP5k/3jq1jTcHmCQcsL1r1sjazIvfLyYreU7NDQbnY5oS9ffkSSA7URsF3bp8C832 6wM/WuaqELiMcGXeGuxXafXTR5Y2DAVKqGCaVTqz07mo1hKj1EdUwSIYLJ2snz/iNzDC mUQ1tlhqBwQOfZKv3jOMnZcnk8xLJaYauofotiso7IxkidG0rh2vZhPO3bPa70in32QL evqqcHmHQ+9oLV/+GOhd6x9AlMpg2L7dco01qCVVJQkoWF25hR6ug8VWRF9svfgQfjQN Q0NQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=bzigehbcQp2xPHlY/w//Q49HPM6uLRH5KPdZ1KYam60=; b=PxlaviKVt1/n07W8OYs3sc3ATqa6jvzV2nK6YKIdnZ1ueaSAiiBTGpdhsNTOw8HjXW jf25rqqxKQr7oIm0UuSojXmt5jMnZy1xmFzLLSYSeqxLlzA2SzLhdwW1QmpFp+FS0DSB x3GBa8vGz6DBg4FMLbuNoqsZruTdj0ydu4xUY3yVNDtaoEjRovNV04TlZtWJCB/n7riX 0Msm4J3aIfB7gDx3J359DNlZ5EodK8f0SQH1e4z1gEwtEIktSVOLrzV3wjr0W3C1ck2L G8NtQk6cks5s4YejOriTmImvAXH3X2BDkun+EQZb/BRZ+e0oNjAVjECMfKEL3eTWtiNm 4Dcw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g15-v6si1999236plo.284.2018.09.05.07.34.48; Wed, 05 Sep 2018 07:34:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727679AbeIETFE (ORCPT + 32 others); Wed, 5 Sep 2018 15:05:04 -0400 Received: from foss.arm.com ([217.140.101.70]:59164 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726046AbeIETFE (ORCPT ); Wed, 5 Sep 2018 15:05:04 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A2E9B1596; Wed, 5 Sep 2018 07:34:36 -0700 (PDT) Received: from edgewater-inn.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 743BE3F739; Wed, 5 Sep 2018 07:34:36 -0700 (PDT) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id DA2221AE2F82; Wed, 5 Sep 2018 15:34:50 +0100 (BST) From: Will Deacon To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, arnd@arndb.de, linux@dominikbrodowski.net, ebiederm@xmission.com, akpm@linux-foundation.org, viro@zeniv.linux.org.uk, oleg@redhat.com, steve.mcintyre@arm.com, dave.martin@arm.com, Will Deacon Subject: [RESEND PATCH 1/2] signal: Introduce COMPAT_SIGMINSTKSZ for use in compat_sys_sigaltstack Date: Wed, 5 Sep 2018 15:34:42 +0100 Message-Id: <1536158083-30166-2-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1536158083-30166-1-git-send-email-will.deacon@arm.com> References: <1536158083-30166-1-git-send-email-will.deacon@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The sigaltstack(2) system call fails with -ENOMEM if the new alternative signal stack is found to be smaller than SIGMINSTKSZ. On architectures such as arm64, where the native value for SIGMINSTKSZ is larger than the compat value, this can result in an unexpected error being reported to a compat task. See, for example: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=904385 This patch fixes the problem by extending do_sigaltstack to take the minimum signal stack size as an additional parameter, allowing the native and compat system call entry code to pass in their respective values. COMPAT_SIGMINSTKSZ is just defined as SIGMINSTKSZ if it has not been defined by the architecture. Cc: Arnd Bergmann Cc: Dominik Brodowski Cc: "Eric W. Biederman" Cc: Andrew Morton Cc: Al Viro Cc: Oleg Nesterov Reported-by: Steve McIntyre Signed-off-by: Will Deacon --- include/linux/compat.h | 3 +++ kernel/signal.c | 14 +++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) -- 2.1.4 diff --git a/include/linux/compat.h b/include/linux/compat.h index 1a3c4f37e908..de0c13bdcd2c 100644 --- a/include/linux/compat.h +++ b/include/linux/compat.h @@ -103,6 +103,9 @@ typedef struct compat_sigaltstack { compat_size_t ss_size; } compat_stack_t; #endif +#ifndef COMPAT_MINSIGSTKSZ +#define COMPAT_MINSIGSTKSZ MINSIGSTKSZ +#endif #define compat_jiffies_to_clock_t(x) \ (((unsigned long)(x) * COMPAT_USER_HZ) / HZ) diff --git a/kernel/signal.c b/kernel/signal.c index 5843c541fda9..e4aad0e90882 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -3460,7 +3460,8 @@ int do_sigaction(int sig, struct k_sigaction *act, struct k_sigaction *oact) } static int -do_sigaltstack (const stack_t *ss, stack_t *oss, unsigned long sp) +do_sigaltstack (const stack_t *ss, stack_t *oss, unsigned long sp, + size_t min_ss_size) { struct task_struct *t = current; @@ -3490,7 +3491,7 @@ do_sigaltstack (const stack_t *ss, stack_t *oss, unsigned long sp) ss_size = 0; ss_sp = NULL; } else { - if (unlikely(ss_size < MINSIGSTKSZ)) + if (unlikely(ss_size < min_ss_size)) return -ENOMEM; } @@ -3508,7 +3509,8 @@ SYSCALL_DEFINE2(sigaltstack,const stack_t __user *,uss, stack_t __user *,uoss) if (uss && copy_from_user(&new, uss, sizeof(stack_t))) return -EFAULT; err = do_sigaltstack(uss ? &new : NULL, uoss ? &old : NULL, - current_user_stack_pointer()); + current_user_stack_pointer(), + MINSIGSTKSZ); if (!err && uoss && copy_to_user(uoss, &old, sizeof(stack_t))) err = -EFAULT; return err; @@ -3519,7 +3521,8 @@ int restore_altstack(const stack_t __user *uss) stack_t new; if (copy_from_user(&new, uss, sizeof(stack_t))) return -EFAULT; - (void)do_sigaltstack(&new, NULL, current_user_stack_pointer()); + (void)do_sigaltstack(&new, NULL, current_user_stack_pointer(), + MINSIGSTKSZ); /* squash all but EFAULT for now */ return 0; } @@ -3553,7 +3556,8 @@ static int do_compat_sigaltstack(const compat_stack_t __user *uss_ptr, uss.ss_size = uss32.ss_size; } ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, - compat_user_stack_pointer()); + compat_user_stack_pointer(), + COMPAT_MINSIGSTKSZ); if (ret >= 0 && uoss_ptr) { compat_stack_t old; memset(&old, 0, sizeof(old)); From patchwork Wed Sep 5 14:34:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 146002 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp5014775ljw; Wed, 5 Sep 2018 07:34:44 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb1YWk9BWfugy+Al+yxzeHhkT7t2fHz/WfLGwuiWwDb7hbGblOplcDktCiZqb2IwYwjeP+T X-Received: by 2002:a65:48c6:: with SMTP id o6-v6mr35646207pgs.99.1536158084361; Wed, 05 Sep 2018 07:34:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536158084; cv=none; d=google.com; s=arc-20160816; b=GY75OA+tfQbREtpYbkYl8oUPeEFvRxqLppZKhN8bKWyONtuGWrnb+/7/uP7rpna8d1 tp2uhLGHNN/PG7RhTdKmP42LTjb7BzUOODd/484gLbCRj8AhqtAviwXJrzTvdOmnKdLP vjuBFshydWGiss6KVJbizmcNRT4fCddZ8VCnT7StuLkr/O4TZJjxYiMDx6rylQYm3/O5 M/h3YH+Gn3MgtlmPRRtr0nHWPfHQw6EwRSADsAFGx3QxxPKCuAuY4b/aMo7silZgmOR6 u4WoPMp3Y0o5wShPq7EZaqSolR9/BjniGQ9PUDCfVMb3TZ3cs06gB0T89u5KS1xhGZZy T4ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=vHKDgX6ebWT7Vs9crfIW+Zq3jPitVxUOdxw68TzB7hY=; b=JEsER8Kv4vpnzzGYEj5Af7Ffkxy4nvJRY8m98sa4iHDZdhEysDgpQbP6anItq068dr nXN7X/blGL0gfFv1cUh391ewO5pSGFkcSo0kCeeMS9AlXEV3d81UPoAkRBt+ZOjE0xLK 9gMC3QcbDOdH09YThVAawl9+IO2eMmaeL+9dfJejt2C7XT4+ImcLn51uzy1EArpl2ywJ 1EqO66/80AZPoYYns66fRhaTa+gI60dVogGAsshWyyg5pYBnFaaoFL3pjYUno6FtioD+ DYDeZ7nxI0eDXp3Tt9q6kTUX+XB9++YF+qtUtK53V40GKYhokDtWTIqJA38K9YwtVpNi MaxA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z127-v6si2159256pgz.370.2018.09.05.07.34.44; Wed, 05 Sep 2018 07:34:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727704AbeIETFE (ORCPT + 32 others); Wed, 5 Sep 2018 15:05:04 -0400 Received: from foss.arm.com ([217.140.101.70]:59168 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727234AbeIETFE (ORCPT ); Wed, 5 Sep 2018 15:05:04 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B402715B2; Wed, 5 Sep 2018 07:34:36 -0700 (PDT) Received: from edgewater-inn.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 859673F77D; Wed, 5 Sep 2018 07:34:36 -0700 (PDT) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id E74D41AE358D; Wed, 5 Sep 2018 15:34:50 +0100 (BST) From: Will Deacon To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, arnd@arndb.de, linux@dominikbrodowski.net, ebiederm@xmission.com, akpm@linux-foundation.org, viro@zeniv.linux.org.uk, oleg@redhat.com, steve.mcintyre@arm.com, dave.martin@arm.com, Will Deacon Subject: [RESEND PATCH 2/2] arm64: compat: Provide definition for COMPAT_SIGMINSTKSZ Date: Wed, 5 Sep 2018 15:34:43 +0100 Message-Id: <1536158083-30166-3-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1536158083-30166-1-git-send-email-will.deacon@arm.com> References: <1536158083-30166-1-git-send-email-will.deacon@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org arch/arm/ defines a SIGMINSTKSZ of 2k, so we should use the same value for compat tasks. Cc: Arnd Bergmann Cc: Dominik Brodowski Cc: "Eric W. Biederman" Cc: Andrew Morton Cc: Al Viro Cc: Oleg Nesterov Reviewed-by: Dave Martin Reported-by: Steve McIntyre Signed-off-by: Will Deacon --- arch/arm64/include/asm/compat.h | 1 + 1 file changed, 1 insertion(+) -- 2.1.4 diff --git a/arch/arm64/include/asm/compat.h b/arch/arm64/include/asm/compat.h index 1a037b94eba1..cee28a05ee98 100644 --- a/arch/arm64/include/asm/compat.h +++ b/arch/arm64/include/asm/compat.h @@ -159,6 +159,7 @@ static inline compat_uptr_t ptr_to_compat(void __user *uptr) } #define compat_user_stack_pointer() (user_stack_pointer(task_pt_regs(current))) +#define COMPAT_MINSIGSTKSZ 2048 static inline void __user *arch_compat_alloc_user_space(long len) {