From patchwork Wed Jul 25 13:45:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 142859 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp839270ljj; Wed, 25 Jul 2018 06:45:42 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdKh08+5M2mF/iz+4tvoqq9VIZOhmHoGU4wl3n9idc42CNqlp9VuFlNV6Waaefcctdl3RlL X-Received: by 2002:a17:902:4c88:: with SMTP id b8-v6mr20370871ple.285.1532526342391; Wed, 25 Jul 2018 06:45:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532526342; cv=none; d=google.com; s=arc-20160816; b=Nr1T/3hRcuH9aURJVa3snU4l2ZwqSzK8ZNpOUaNAu4SPMNa6ZGPQ00X8s4GIJeeC7w uJ+jAbm32wCTzEc3OW7DhNbpcpc85xnrfGGy7Bwlj2So22oxkrai8kxhUnuSNAkmaFOW g8LWJ/kVxOwcepIPgUMARq2j1cmeOdru1Nw3raH5PFoDQe+Iw4HrbuTHk/oyBocVC6Sh D1vMlT89hGFDjR3NXKalE76A9PFoithEv3NMOCaK2jHX2fDUpCipGKasOmbLmkTtRk3F 9BUpB2vMQ7tcDOsohqlCAk95fSj35tjd+l0kw0kyWI+pAXk3gOLjFyDWP37SL37NQJka StLQ== 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:arc-authentication-results; bh=cohxF/amrwwhsJe0AxdYEP/vlxzSD/0gqVTZojwXDCo=; b=mKC73mIG6Mi2AgNrp6OBfGBb5wcwLbJ00ip51V9SdPwhPXyQTA4q+N4czs1w7VVvuP X2DpA/QA4FbCbwON8qi3ol/ZKkoLY4DuJN5DxRJmLMko6A6pgk/+0vQenx2DLzUd987i SenN6y/EONdoDw8iY7+FpIMYuZnTWsJZI/eLnoA+LkNYdIMVdEATTFY1sIKqm8A5GeTS t/d8ibtSFOyfBoJd0vcchD+fTxIThYlaOBot749wskrceL8UjAZOq9XKAXG2AvnpZWlv Up2mGwv83XLmDcOTqxgyv1p8FtbqOAFa33nh2vqvluFrEa5fJ9+cf1Y1AzfdsntzOO5t +GQA== 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 25-v6si14526427pfp.108.2018.07.25.06.45.42; Wed, 25 Jul 2018 06:45:42 -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 S1729353AbeGYO5C (ORCPT + 31 others); Wed, 25 Jul 2018 10:57:02 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:39038 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729318AbeGYO5C (ORCPT ); Wed, 25 Jul 2018 10:57:02 -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 906EA15B2; Wed, 25 Jul 2018 06:45:17 -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 628EB3F7C7; Wed, 25 Jul 2018 06:45:17 -0700 (PDT) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id 52A201AE0784; Wed, 25 Jul 2018 14:45:17 +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: [PATCH 1/2] signal: Introduce COMPAT_SIGMINSTKSZ for use in compat_sys_sigaltstack Date: Wed, 25 Jul 2018 14:45:11 +0100 Message-Id: <1532526312-26993-2-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1532526312-26993-1-git-send-email-will.deacon@arm.com> References: <1532526312-26993-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 c68acc47da57..47041c7fed28 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 8d8a940422a8..41a5dd2df27d 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -3417,7 +3417,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; @@ -3447,7 +3448,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; } @@ -3465,7 +3466,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; @@ -3476,7 +3478,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; } @@ -3510,7 +3513,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));