Received: by 10.223.176.46 with SMTP id f43csp4698824wra; Tue, 23 Jan 2018 13:11:09 -0800 (PST) X-Google-Smtp-Source: AH8x226042tIgOj0+SmjWoQTYSpMaGyx6WSFEyAjozYtevkBB3je1YtTttczJyhYWkUNMsZtq9An X-Received: by 10.36.26.137 with SMTP id 131mr5570005iti.25.1516741869887; Tue, 23 Jan 2018 13:11:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516741869; cv=none; d=google.com; s=arc-20160816; b=ycAxgKbuvwsIe/KeUx2usMdiK/U4PagLWN9Su0fstU7uJPmHspR5h8EPGt1mnWb2Ea DbBNIG3iFBjawmmWkuAx1oADQkd67jmOXAEvwg9ItEKk4tD+Rcv//54nMg9cbUr0MNHZ IX5/X17m6dQ4FwoMTcYr2k0J6wYGuI5aN4UI12zCBaleAwTtQj8Qnbdl8opf/Yg46gbM I0ggh4ER6/Rw9Q2pYow+x32F6cqI5UXxI1R0CumP9JY+UQLFkQaPCLTQzy19DLWMHPSD FwF7gsyuJ7Pn1PGVS9XS0Ggkk/FRtLb6/TsS2J7EtmEbasqWS1onLQbg+xBm18dMhU8S U7xw== 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=TC5AgW+KTizwJxjTntJgCkD5EHQ0Fh240SgWUFZyYlE=; b=ZRWzDpdUFnTB5z15WCdaddz6wjcEVpgMucp1YDLxy4vEmoSDmIYW2Mz+vkBjF9yaze cLTwxsfmIY4fJerS12FBK4hmsQ21DHT5xZnDsIyeR7y7PE8bQw6UwV12OGISsZx4TOps skUotlgSSm8+n11MUC+tJm6B/WW/M5yEGi7ePtYmiCvOOM5jyjVZehjIgSThS00Xn9kc Xg4XorBOXbYzjIkGxnT3wfS9uNXxpxklhCJ3b4FHmVY22i6jN02V0Ager+56rRUJ88Rt A1oL11HJ58XxmABnumQBGLAEHVo/Cl0SL/tMk74acgNBruncaTbUrDYbSsSWe4cnFP29 +ZTQ== 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 h71si15898243ioe.267.2018.01.23.13.10.55; Tue, 23 Jan 2018 13:11:09 -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 S932393AbeAWVKH (ORCPT + 99 others); Tue, 23 Jan 2018 16:10:07 -0500 Received: from out01.mta.xmission.com ([166.70.13.231]:46693 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932269AbeAWVJL (ORCPT ); Tue, 23 Jan 2018 16:09:11 -0500 Received: from in01.mta.xmission.com ([166.70.13.51]) by out01.mta.xmission.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.87) (envelope-from ) id 1ee5oc-0001bY-KH; Tue, 23 Jan 2018 14:09:10 -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 1ee5oa-0003u7-Sq; Tue, 23 Jan 2018 14:09:10 -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:15 -0600 Message-Id: <20180123210719.10456-6-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=1ee5oa-0003u7-Sq;;;mid=<20180123210719.10456-6-ebiederm@xmission.com>;;;hst=in01.mta.xmission.com;;;ip=97.121.88.104;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX19CqvRGVJfwoVMD30Gqdvk7KGbXOH7bfzg= 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 sa06.xmission.com X-Spam-Level: ** X-Spam-Status: No, score=2.0 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,TVD_RCVD_IP,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 * 1.5 XMNoVowels Alpha-numberic number with no vowels * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa06 1397; Body=1 Fuz1=1 Fuz2=1] X-Spam-DCC: XMission; sa06 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: **;linux-kernel@vger.kernel.org X-Spam-Relay-Country: X-Spam-Timing: total 1337 ms - load_scoreonly_sql: 0.05 (0.0%), signal_user_changed: 2.4 (0.2%), b_tie_ro: 1.53 (0.1%), parse: 1.12 (0.1%), extract_message_metadata: 16 (1.2%), get_uri_detail_list: 3.3 (0.2%), tests_pri_-1000: 7 (0.6%), tests_pri_-950: 1.49 (0.1%), tests_pri_-900: 1.29 (0.1%), tests_pri_-400: 38 (2.8%), check_bayes: 36 (2.7%), b_tokenize: 14 (1.0%), b_tok_get_all: 6 (0.5%), b_comp_prob: 3.0 (0.2%), b_tok_touch_all: 11 (0.9%), b_finish: 0.60 (0.0%), tests_pri_0: 1262 (94.4%), check_dkim_signature: 0.71 (0.1%), check_dkim_adsp: 2.9 (0.2%), tests_pri_500: 3.6 (0.3%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 06/10] signal: Helpers for faults with specialized siginfo layouts 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 The helpers added are: send_sig_mceerr force_sig_mceerr force_sig_bnderr force_sig_pkuerr Filling out siginfo properly can ge tricky. Especially for these specialized cases where the temptation is to share code with other cases which use a different subset of siginfo fields. Unfortunately that code sharing frequently results in bugs with the wrong siginfo fields filled in, and makes it harder to verify that the siginfo structure was properly initialized. Provide these helpers instead that get all of the details right, and guarantee that siginfo is properly initialized. send_sig_mceerr and force_sig_mceer are a little special as two si codes BUS_MCEERR_AO and BUS_MCEER_AR both use the same extended signinfo layout. Signed-off-by: "Eric W. Biederman" --- include/linux/sched/signal.h | 6 +++++ kernel/signal.c | 61 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h index 375f31eb3b6b..944fe6356f4a 100644 --- a/include/linux/sched/signal.h +++ b/include/linux/sched/signal.h @@ -305,6 +305,12 @@ int send_sig_fault(int sig, int code, void __user *addr ___ARCH_SI_IA64(int imm, unsigned int flags, unsigned long isr) , struct task_struct *t); +int force_sig_mceerr(int code, void __user *, short, struct task_struct *); +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); + 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 15ec7b3cbe69..4f6300ef8062 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -1537,6 +1537,67 @@ int send_sig_fault(int sig, int code, void __user *addr return send_sig_info(info.si_signo, &info, t); } +#if defined(BUS_MCEERR_AO) && defined(BUS_MCEERR_AR) +int force_sig_mceerr(int code, void __user *addr, short lsb, struct task_struct *t) +{ + struct siginfo info; + + WARN_ON((code != BUS_MCEERR_AO) && (code != BUS_MCEERR_AR)); + clear_siginfo(&info); + info.si_signo = SIGBUS; + info.si_errno = 0; + info.si_code = code; + info.si_addr = addr; + info.si_addr_lsb = lsb; + return force_sig_info(info.si_signo, &info, t); +} + +int send_sig_mceerr(int code, void __user *addr, short lsb, struct task_struct *t) +{ + struct siginfo info; + + WARN_ON((code != BUS_MCEERR_AO) && (code != BUS_MCEERR_AR)); + clear_siginfo(&info); + info.si_signo = SIGBUS; + info.si_errno = 0; + info.si_code = code; + info.si_addr = addr; + info.si_addr_lsb = lsb; + return send_sig_info(info.si_signo, &info, t); +} +EXPORT_SYMBOL(send_sig_mceerr); +#endif + +#ifdef SEGV_BNDERR +int force_sig_bnderr(void __user *addr, void __user *lower, void __user *upper) +{ + struct siginfo info; + + clear_siginfo(&info); + info.si_signo = SIGSEGV; + info.si_errno = 0; + info.si_code = SEGV_BNDERR; + info.si_addr = addr; + info.si_lower = lower; + info.si_upper = upper; + return force_sig_info(info.si_signo, &info, current); +} +#endif + +#ifdef SEGV_PKUERR +int force_sig_pkuerr(void __user *addr, u32 pkey) +{ + struct siginfo info; + + clear_siginfo(&info); + info.si_signo = SIGSEGV; + info.si_errno = 0; + info.si_code = SEGV_PKUERR; + info.si_addr = addr; + info.si_pkey = pkey; + return force_sig_info(info.si_signo, &info, current); +} +#endif int kill_pgrp(struct pid *pid, int sig, int priv) { -- 2.14.1