Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp176951imd; Wed, 31 Oct 2018 16:52:10 -0700 (PDT) X-Google-Smtp-Source: AJdET5edDwogJFKCtNPDNAWcxZsMVYn831hcpihdKIBVFlgFvfUMELfOk6RAuKTBsYCOHPxgI/RG X-Received: by 2002:a17:902:4381:: with SMTP id j1-v6mr5267359pld.59.1541029930791; Wed, 31 Oct 2018 16:52:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541029930; cv=none; d=google.com; s=arc-20160816; b=Wn67uW6HM1ODUvb0y0Dx7t7i7vTVo4CJg0ifzcuBHEqrgGB+pOK4g6lsfpXSXPoxss vodZRoEltYnYb0GkXRclJty2vsaEvcRqdku55AXWQ2kv9K7UVpL37zFNnP+NwZcTgOu5 C9IiS2cTgOPTdwW/Si8tyHqp35XbmsEs6KFJ2YcGmen6NzjezX+8RUz1iwz4oslhExHc I9qTWaad+ukOmcRDmEEEVnWWlbjO7HTC3dW/ARujoNjwiTkXFDE20JywfZWp7VUTkHES ANiXEDdYnKCAf6YJM+oaIxYVBKui0lF/oYdi0KRsCXMwXHPvT9Ox9jwym4EQb8i39HXq tMtA== 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:dkim-signature; bh=gpaxxmyCSKdjZhQdoDKaPRq+2VzTXdsIR009LNIRRG0=; b=Qstk2ZahDUCvhCMInB6a/LhBBeQO2WLPwjjE1bBmWFC2Wb+Iyxm4m0KabX01HUvZyT Q9Y10KjYoHigbQ9v1TKNNOjDEuXKwtcUzjz+7nf+rYTG1xn+ue6OaPjcZ9CFjikNYMA2 J0tJuOZud3H5fofH3fcoLOOQT+4TMVv8+bXa8QAku6MMfeY9dYX7LXt3wlACPXpN0ETn b7JY/NcJysh/X+GAmN+mQBtwsjZopyxuCJsbBqV49YA8qPYyy4shD0YakcliWwzvQpHv 3MDg+U0qnNEx2Sn6JUCl+ihQwtdjirR+i1OzP6ClBm9qtNBBRVTyBhbk2bnH1zkbl+FD yq7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Xek6CXhM; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cb11-v6si15143264plb.227.2018.10.31.16.51.55; Wed, 31 Oct 2018 16:52:10 -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; dkim=pass header.i=@kernel.org header.s=default header.b=Xek6CXhM; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728078AbeKAIGc (ORCPT + 99 others); Thu, 1 Nov 2018 04:06:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:53400 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728043AbeKAIGa (ORCPT ); Thu, 1 Nov 2018 04:06:30 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8E7D820830; Wed, 31 Oct 2018 23:06:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027180; bh=d3jqBbn/9Poqv+I1jgwvudd2LkeSuMY+WqtBmXR3PZo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xek6CXhMUK8Oq2vs+bkrspkfKWceaDsE818ldUN7IAo8RB20nmODw6ivbJQPDgjfz 24vT0XjMjYwlAtDoJ4nmzB/UD6E5RFCy0q5V59U20stQ36B9ifQF7rHfEEj948OQb4 3WZCHRscBCOK0F4TIECMd6/MMhN8GmjiYD/sLQVE= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Will Deacon , Arnd Bergmann , Dominik Brodowski , "Eric W. Biederman" , Andrew Morton , Al Viro , Oleg Nesterov , Catalin Marinas , Sasha Levin Subject: [PATCH AUTOSEL 4.19 042/146] signal: Introduce COMPAT_SIGMINSTKSZ for use in compat_sys_sigaltstack Date: Wed, 31 Oct 2018 19:03:57 -0400 Message-Id: <20181031230541.28822-42-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031230541.28822-1-sashal@kernel.org> References: <20181031230541.28822-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- include/linux/compat.h | 3 +++ kernel/signal.c | 14 +++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) 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)); -- 2.17.1