Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3438749imu; Sun, 11 Nov 2018 15:06:42 -0800 (PST) X-Google-Smtp-Source: AJdET5drJH1KigwG9gJs0f8Ed5OrHHknfHpyADLnliIRdlBkYD6NhSVPxi4r9/ES5hnE9NkZiAY9 X-Received: by 2002:a63:fc22:: with SMTP id j34-v6mr15637353pgi.434.1541977602917; Sun, 11 Nov 2018 15:06:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541977602; cv=none; d=google.com; s=arc-20160816; b=pdQB4Z9/9B8twd0g39Bs+FG8Rx/PSbr/cA/+/IhuPwkjXBVO8bycFg3Nfl2yzwUCqq HWj1YhS4y7oaV2dDXlz2CyNiLSjCOj1eeV4CpFRX0Ej7rTnA0iTFvI9mfBxqnx+38aH/ nElq9zHf6mJBgnVd9V3pPvujJlZdvxlWhY0yXmADytNp3Ang70vK2GNVuLrprO8YVil0 hp3b9i3DDgcvfrm24+EBeVVvkmT3ya7Bkc8G3Dc9p9ZXb5f+DRBL4tjLsmO9gHBdVd/f gqM/Wk+c+xgS0d1uMlm4WARJpI1QlldlauyS5XYnKbonOllTQ6UZVLGVwdeDbF7kPw2Z DmBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=F44xUV4v7drYzkOVu3znExl5u7TWcQ+lAaWH79UFf7A=; b=iLWSOe/lAMW9CbRx3chPnBayMVkF3kYZRxCwgMXan9zq7VRhk8BBB9MGQTqYgLy+m2 bg2UmQAdEpEeHD4+kZLGd0XGhh6RZKaU8M2zc26dPv3a3ygLqtrXfkf5u5YyInNwdBB9 UW58qf7/71Yd65XHAtxawlvu85B5Ap9RTqjR97MIkfNTfINwZWNAZr+AHHl+XOOs2g+f gff/UJaZeUuL85tevqLjR4RHasKv9YOHSRVJnb7dfSXgjEp4vF6XosXzln4yTT6GDtAS n1DHwUhnHp7oa2CIY1ODh5/Z8DnZC1qcEsZpTzimlcOU8JT0MZM0i6XDdfqZKLpZt+0A m/jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=E1uKRtNb; 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 d3-v6si18215210pln.204.2018.11.11.15.06.27; Sun, 11 Nov 2018 15:06:42 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=E1uKRtNb; 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 S2390463AbeKLIWR (ORCPT + 99 others); Mon, 12 Nov 2018 03:22:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:51836 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387738AbeKLIWQ (ORCPT ); Mon, 12 Nov 2018 03:22:16 -0500 Received: from localhost (unknown [206.108.79.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CB4BF21707; Sun, 11 Nov 2018 22:32:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975538; bh=PS3h088FvS5XHJwtGvcD0JSUsbbCaxoqxT7jqJHUSak=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E1uKRtNbthjjYPEr5Qj7v64RAKT8H/zcoY6UsqSFEfKlHUqCwNPuFSN2GQTrXftsi nmIAsQnHeRX+jE8gGXRVlkF0CWonN3ftwHjyEFRzLddse1wI4ioAxwzzEoVBTw77GD VqfL+oJfkSkTOaP6RAn+4EGvkuudQThzIIasq36k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arnd Bergmann , Dominik Brodowski , "Eric W. Biederman" , Andrew Morton , Al Viro , Oleg Nesterov , Steve McIntyre , Steve McIntyre <93sam@debian.org>, Will Deacon , Catalin Marinas , Sasha Levin Subject: [PATCH 4.14 059/222] signal: Introduce COMPAT_SIGMINSTKSZ for use in compat_sys_sigaltstack Date: Sun, 11 Nov 2018 14:22:36 -0800 Message-Id: <20181111221653.294905948@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221647.665769131@linuxfoundation.org> References: <20181111221647.665769131@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Will Deacon [ Upstream commit 22839869f21ab3850fbbac9b425ccc4c0023926f ] 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 Tested-by: Steve McIntyre <93sam@debian.org> Signed-off-by: Will Deacon Signed-off-by: Catalin Marinas Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- include/linux/compat.h | 3 +++ kernel/signal.c | 14 +++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) --- a/include/linux/compat.h +++ b/include/linux/compat.h @@ -68,6 +68,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) --- a/kernel/signal.c +++ b/kernel/signal.c @@ -3215,7 +3215,8 @@ int do_sigaction(int sig, struct k_sigac } 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; @@ -3245,7 +3246,7 @@ do_sigaltstack (const stack_t *ss, stack ss_size = 0; ss_sp = NULL; } else { - if (unlikely(ss_size < MINSIGSTKSZ)) + if (unlikely(ss_size < min_ss_size)) return -ENOMEM; } @@ -3263,7 +3264,8 @@ SYSCALL_DEFINE2(sigaltstack,const stack_ 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; @@ -3274,7 +3276,8 @@ int restore_altstack(const stack_t __use 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; } @@ -3309,7 +3312,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack, 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));