Received: by 10.223.176.46 with SMTP id f43csp4698994wra; Tue, 23 Jan 2018 13:11:20 -0800 (PST) X-Google-Smtp-Source: AH8x224ExwJaMikw0Go6BDdbFj/k9xh1cMrSmlp2CN62kgGBgrUxuOQ/MB0slPs9WiT1Um8K+dS7 X-Received: by 10.36.241.65 with SMTP id q1mr5416372iti.4.1516741880827; Tue, 23 Jan 2018 13:11:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516741880; cv=none; d=google.com; s=arc-20160816; b=RqS9y/ibaLV9xER8aDX47sOt7NLSvEBpk04FNmGNDrYtsGuBpuh2PFIHSIYKyTJOOe B6trQCMB2FcSnjVq5QgnBt/ToKKuslUbFqGe7imilaw1KZQURU1XOfLXyvUDikpiha0K mop7AFaJOb6xWyTl79gO/hHmMhqp6greuxs72rxKF+8fg6uFYpApFNJo0dc/Ya+BMYyd 6RaHazKt3MF/3sh0dAIly4zYILrMHw/VHZRn7aQ/7L+MtBpAid7OUrK3KElT88Eaielr qL3AM6r79CQO7Z3Mr6tO332py/YfEIoY3nlg9YIAzTVzA+UOujP7Q2WSFKqWoKs1938v yJDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:references:in-reply-to:message-id :date:cc:to:from:arc-authentication-results; bh=9T9s0yJgsZg8tyk4HrwYHOnNDnEfJ6sQpa7AsX/ZEsI=; b=uY2O0g2+GCsh6rsIdNEfpb1P8wvPUCBDbeaIEbxJk4cs2c609IEq8gPu1zcpf9qeR/ LW00BKmffDska67Qs//Lyp2Pb4/pLUXcD7iErw0/CY7MpfpBy94T+G+ZakGmjqqS/z07 vff7ORf/twvMQM5sX52z5LdhdcQtsgvDX9IhNB0snNANznfDfD4R230vuHJqFlr0MvDf BpGtVT4mfyOhqGY6l2cF5gVAlO3BJMBfH4+S8nAQet5w8nMVff/TtO8q4LeQd58AXifk eaOaB8kVw5LU+B/z+oG+BDR4Is8AxOXGd5P/QU1ZRhez69xiuLx7E2fi36m6hnd/rocJ HSpQ== 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 j131si10387711ioj.178.2018.01.23.13.11.07; Tue, 23 Jan 2018 13:11:20 -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; 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 S932371AbeAWVKD (ORCPT + 99 others); Tue, 23 Jan 2018 16:10:03 -0500 Received: from out03.mta.xmission.com ([166.70.13.233]:51926 "EHLO out03.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932293AbeAWVJR (ORCPT ); Tue, 23 Jan 2018 16:09:17 -0500 Received: from in01.mta.xmission.com ([166.70.13.51]) by out03.mta.xmission.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.87) (envelope-from ) id 1ee5oi-0001Qs-Nu; Tue, 23 Jan 2018 14:09:16 -0700 Received: from 97-121-88-104.omah.qwest.net ([97.121.88.104] helo=x220.int.ebiederm.org) by in01.mta.xmission.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.87) (envelope-from ) id 1ee5og-0003u7-VU; Tue, 23 Jan 2018 14:09:16 -0700 From: "Eric W. Biederman" To: linux-kernel@vger.kernel.org Cc: Al Viro , Oleg Nesterov , linux-arch@vger.kernel.org, Ram Pai , "Eric W. Biederman" Date: Tue, 23 Jan 2018 15:07:17 -0600 Message-Id: <20180123210719.10456-8-ebiederm@xmission.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <87607s5lra.fsf_-_@xmission.com> References: <87607s5lra.fsf_-_@xmission.com> X-XM-SPF: eid=1ee5og-0003u7-VU;;;mid=<20180123210719.10456-8-ebiederm@xmission.com>;;;hst=in01.mta.xmission.com;;;ip=97.121.88.104;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1/R/GvH908jUHuKx9ESnyD05xXDdKbSt6I= X-SA-Exim-Connect-IP: 97.121.88.104 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on sa07.xmission.com X-Spam-Level: *** X-Spam-Status: No, score=3.5 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,TVD_RCVD_IP,T_TooManySym_01,XMGappySubj_01,XMGappySubj_02, XMNoVowels,XMSubLong autolearn=disabled version=3.4.1 X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.0 TVD_RCVD_IP Message was received from an IP address * 0.7 XMSubLong Long Subject * 0.5 XMGappySubj_01 Very gappy subject * 1.5 XMNoVowels Alpha-numberic number with no vowels * 1.0 XMGappySubj_02 Gappier still * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa07 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_01 4+ unique symbols in subject X-Spam-DCC: XMission; sa07 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ***;linux-kernel@vger.kernel.org X-Spam-Relay-Country: X-Spam-Timing: total 1387 ms - load_scoreonly_sql: 0.03 (0.0%), signal_user_changed: 3.1 (0.2%), b_tie_ro: 2.3 (0.2%), parse: 0.94 (0.1%), extract_message_metadata: 11 (0.8%), get_uri_detail_list: 3.1 (0.2%), tests_pri_-1000: 5 (0.4%), tests_pri_-950: 1.49 (0.1%), tests_pri_-900: 1.11 (0.1%), tests_pri_-400: 31 (2.2%), check_bayes: 29 (2.1%), b_tokenize: 12 (0.9%), b_tok_get_all: 8 (0.5%), b_comp_prob: 2.2 (0.2%), b_tok_touch_all: 3.6 (0.3%), b_finish: 0.55 (0.0%), tests_pri_0: 1325 (95.5%), check_dkim_signature: 0.57 (0.0%), check_dkim_adsp: 2.6 (0.2%), tests_pri_500: 5 (0.4%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 08/10] signal/ptrace: Add force_sig_ptrace_errno_trap and use it where needed X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are so many places that build struct siginfo by hand that at least one of them is bound to get it wrong. A handful of cases in the kernel arguably did just that when using the errno field of siginfo to pass no errno values to userspace. The usage is limited to a single si_code so at least does not mess up anything else. Encapsulate this questionable pattern in a helper function so that the userspace ABI is preserved. Update all of the places that use this pattern to use the new helper function. Signed-off-by: "Eric W. Biederman" --- arch/arm/kernel/ptrace.c | 8 +------- arch/arm64/kernel/ptrace.c | 6 ++++-- arch/powerpc/kernel/process.c | 9 ++------- arch/xtensa/kernel/ptrace.c | 8 +------- include/linux/sched/signal.h | 2 ++ kernel/signal.c | 15 +++++++++++++++ 6 files changed, 25 insertions(+), 23 deletions(-) diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c index 58e3771e4c5b..7724b0f661b3 100644 --- a/arch/arm/kernel/ptrace.c +++ b/arch/arm/kernel/ptrace.c @@ -390,7 +390,6 @@ static void ptrace_hbptriggered(struct perf_event *bp, struct arch_hw_breakpoint *bkpt = counter_arch_bp(bp); long num; int i; - siginfo_t info; for (i = 0; i < ARM_MAX_HBP_SLOTS; ++i) if (current->thread.debug.hbp[i] == bp) @@ -398,12 +397,7 @@ static void ptrace_hbptriggered(struct perf_event *bp, num = (i == ARM_MAX_HBP_SLOTS) ? 0 : ptrace_hbp_idx_to_num(i); - info.si_signo = SIGTRAP; - info.si_errno = (int)num; - info.si_code = TRAP_HWBKPT; - info.si_addr = (void __user *)(bkpt->trigger); - - force_sig_info(SIGTRAP, &info, current); + force_sig_ptrace_errno_trap((int)num, (void __user *)(bkpt->trigger)); } /* diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 95daa1478a7c..6618036ae6d4 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -190,21 +190,23 @@ static void ptrace_hbptriggered(struct perf_event *bp, #ifdef CONFIG_COMPAT if (is_compat_task()) { + int si_errno = 0; int i; for (i = 0; i < ARM_MAX_BRP; ++i) { if (current->thread.debug.hbp_break[i] == bp) { - info.si_errno = (i << 1) + 1; + si_errno = (i << 1) + 1; break; } } for (i = 0; i < ARM_MAX_WRP; ++i) { if (current->thread.debug.hbp_watch[i] == bp) { - info.si_errno = -((i << 1) + 1); + si_errno = -((i << 1) + 1); break; } } + force_sig_ptrace_errno_trap(si_errno, (void __user *)bkpt->trigger); } #endif force_sig_info(SIGTRAP, &info, current); diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c index bfb48cf56bc3..4208cbe2fb7f 100644 --- a/arch/powerpc/kernel/process.c +++ b/arch/powerpc/kernel/process.c @@ -603,19 +603,14 @@ EXPORT_SYMBOL(flush_all_to_thread); void do_send_trap(struct pt_regs *regs, unsigned long address, unsigned long error_code, int breakpt) { - siginfo_t info; - current->thread.trap_nr = TRAP_HWBKPT; if (notify_die(DIE_DABR_MATCH, "dabr_match", regs, error_code, 11, SIGSEGV) == NOTIFY_STOP) return; /* Deliver the signal to userspace */ - info.si_signo = SIGTRAP; - info.si_errno = breakpt; /* breakpoint or watchpoint id */ - info.si_code = TRAP_HWBKPT; - info.si_addr = (void __user *)address; - force_sig_info(SIGTRAP, &info, current); + force_sig_ptrace_errno_trap(breakpt, /* breakpoint or watchpoint id */ + (void __user *)address); } #else /* !CONFIG_PPC_ADV_DEBUG_REGS */ void do_break (struct pt_regs *regs, unsigned long address, diff --git a/arch/xtensa/kernel/ptrace.c b/arch/xtensa/kernel/ptrace.c index e2461968efb2..c0845cb1cbb9 100644 --- a/arch/xtensa/kernel/ptrace.c +++ b/arch/xtensa/kernel/ptrace.c @@ -278,7 +278,6 @@ static void ptrace_hbptriggered(struct perf_event *bp, struct pt_regs *regs) { int i; - siginfo_t info; struct arch_hw_breakpoint *bkpt = counter_arch_bp(bp); if (bp->attr.bp_type & HW_BREAKPOINT_X) { @@ -293,12 +292,7 @@ static void ptrace_hbptriggered(struct perf_event *bp, i = (i << 1) | 1; } - info.si_signo = SIGTRAP; - info.si_errno = i; - info.si_code = TRAP_HWBKPT; - info.si_addr = (void __user *)bkpt->address; - - force_sig_info(SIGTRAP, &info, current); + force_sig_ptrace_errno_trap(i, (void __user *)bkpt->address); } static struct perf_event *ptrace_hbp_create(struct task_struct *tsk, int type) diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h index 944fe6356f4a..23b4f9cb82db 100644 --- a/include/linux/sched/signal.h +++ b/include/linux/sched/signal.h @@ -311,6 +311,8 @@ int send_sig_mceerr(int code, void __user *, short, struct task_struct *); int force_sig_bnderr(void __user *addr, void __user *lower, void __user *upper); int force_sig_pkuerr(void __user *addr, u32 pkey); +int force_sig_ptrace_errno_trap(int errno, void __user *addr); + extern int send_sig_info(int, struct siginfo *, struct task_struct *); extern int force_sigsegv(int, struct task_struct *); extern int force_sig_info(int, struct siginfo *, struct task_struct *); diff --git a/kernel/signal.c b/kernel/signal.c index 4f6300ef8062..e549174c0831 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -1599,6 +1599,21 @@ int force_sig_pkuerr(void __user *addr, u32 pkey) } #endif +/* For the crazy architectures that include trap information in + * the errno field, instead of an actual errno value. + */ +int force_sig_ptrace_errno_trap(int errno, void __user *addr) +{ + struct siginfo info; + + clear_siginfo(&info); + info.si_signo = SIGTRAP; + info.si_errno = errno; + info.si_code = TRAP_HWBKPT; + info.si_addr = addr; + return force_sig_info(info.si_signo, &info, current); +} + int kill_pgrp(struct pid *pid, int sig, int priv) { int ret; -- 2.14.1