Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753380AbcCGQxJ (ORCPT ); Mon, 7 Mar 2016 11:53:09 -0500 Received: from smtp43.i.mail.ru ([94.100.177.103]:55413 "EHLO smtp43.i.mail.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752803AbcCGQwU (ORCPT ); Mon, 7 Mar 2016 11:52:20 -0500 From: Stas Sergeev To: stsp@list.ru Cc: Stas Sergeev , Andrew Morton , Oleg Nesterov , "Peter Zijlstra (Intel)" , "Amanieu d'Antras" , Michal Hocko , Richard Weinberger , Vladimir Davydov , Sasha Levin , linux-kernel@vger.kernel.org Subject: [PATCH 2/4] sigaltstack: preparations for adding new SS_xxx flags Date: Mon, 7 Mar 2016 19:52:05 +0300 Message-Id: <1457369527-11452-3-git-send-email-stsp@list.ru> X-Mailer: git-send-email 2.7.2 In-Reply-To: <1457369527-11452-1-git-send-email-stsp@list.ru> References: <1457369527-11452-1-git-send-email-stsp@list.ru> X-Mras: Ok Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2682 Lines: 81 This patch adds SS_FLAG_BITS - the mask that splits sigaltstack mode values and bit-flags. Since there is no bit-flags yet, the mask is defined to 0. The flags are added by subsequent patches. With every new flag, the mask should have the appropriate bit cleared. This makes sure if some flag is tried on a kernel that doesn't support it, the EINVAL error will be returned, because such a flag will be treated as an invalid mode rather than the bit-flag. That way the existence of the particular features can be probed at run-time. This change was suggested by Andy Lutomirski: https://lkml.org/lkml/2016/3/6/158 Signed-off-by: Stas Sergeev CC: Andrew Morton CC: Oleg Nesterov CC: "Peter Zijlstra (Intel)" CC: "Amanieu d'Antras" CC: Michal Hocko CC: Richard Weinberger CC: Vladimir Davydov CC: Sasha Levin CC: linux-kernel@vger.kernel.org --- include/uapi/linux/signal.h | 3 +++ kernel/signal.c | 16 ++++++---------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/include/uapi/linux/signal.h b/include/uapi/linux/signal.h index e1bd50c2..7c73165 100644 --- a/include/uapi/linux/signal.h +++ b/include/uapi/linux/signal.h @@ -7,4 +7,7 @@ #define SS_ONSTACK 1 #define SS_DISABLE 2 +/* mask for all SS_xxx flags */ +#define SS_FLAG_BITS 0 + #endif /* _UAPI_LINUX_SIGNAL_H */ diff --git a/kernel/signal.c b/kernel/signal.c index 0508544..9a24bc3 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -3100,7 +3100,8 @@ do_sigaltstack (const stack_t __user *uss, stack_t __user *uoss, unsigned long s if (uss) { void __user *ss_sp; size_t ss_size; - int ss_flags; + unsigned ss_flags; + int ss_mode; error = -EFAULT; if (!access_ok(VERIFY_READ, uss, sizeof(*uss))) @@ -3115,18 +3116,13 @@ do_sigaltstack (const stack_t __user *uss, stack_t __user *uoss, unsigned long s if (on_sig_stack(sp)) goto out; + ss_mode = ss_flags & ~SS_FLAG_BITS; error = -EINVAL; - /* - * Note - this code used to test ss_flags incorrectly: - * old code may have been written using ss_flags==0 - * to mean ss_flags==SS_ONSTACK (as this was the only - * way that worked) - this fix preserves that older - * mechanism. - */ - if (ss_flags != SS_DISABLE && ss_flags != SS_ONSTACK && ss_flags != 0) + if (ss_mode != SS_DISABLE && ss_mode != SS_ONSTACK && + ss_mode != 0) goto out; - if (ss_flags == SS_DISABLE) { + if (ss_mode == SS_DISABLE) { ss_size = 0; ss_sp = NULL; } else { -- 2.7.2