Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4044779imm; Tue, 25 Sep 2018 10:22:22 -0700 (PDT) X-Google-Smtp-Source: ACcGV603k0aG4P3BJRa8pJF0fZhyvlqq65ioI+mcySR54+FH9KukQmrqwIScGmDCo7k7CkWN21MN X-Received: by 2002:a17:902:f209:: with SMTP id gn9mr2127352plb.173.1537896142573; Tue, 25 Sep 2018 10:22:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537896142; cv=none; d=google.com; s=arc-20160816; b=hrl9f/0Ibibrsn5tH4LZMqX75Kwl5aVAnv2ZMz4vu4cXfSY4PQ2ueFR7gWbzf3jr61 HyAQYPpKQSczDPKYagN9JNAC0L58xrZMiDZlLmntuxNUUyE0LHqXZB1Be4XCms3Ar9p7 eo+5EAN8/9Y4ssnuYed+HJfpjjjAgZcp0SI+DINdWFN0QAE6ntdcSkrDqgeU54DuuYVS ftJE5O8f2aQKwxEQylBEJxeDvv1BOM6nKSqGCfzr/rvYDh5BmKkjsDLKgbAlk5EIV8Lu jD8830L7RAsh0Gb15Qz5syvLEFsH9kMSiK0NqzzV8cTmUJtKPUio59AVbMcVTd2M2Lzv CC4Q== 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; bh=UEWm1b950NKx8/GFVphJCOcjYIK0P1IkbgyD9CLh7/U=; b=hA/2eoXdlUrQBqUPbI39Ho4kgAPbhcT4OqiHvBs6XqxuYJAr7IeICCOPoOx5+S86u8 ajOA4tJwu7+Zmxs2W0N3+h+fsm83IlIhCeSDjD6ytI2AYD+++TalO0Qww60MCe3o8DC/ WvfAvvx0Fgg7ldFx6JAcHAo0Pe6Py1EZlLDdpSXBqQJFe4J4cACsdt7YHqIJSY+pZG37 l49xE71VKMKZJnifo94KOf+tu9bU/pjXiKTK1pAvWgy28E0wEDUjGReUBm36g/zvdubD Q8zY4YZMHFbvprmvLTZ6X6YOxqwaVMTEINZf23tcxK13EEbx7zfglqmInIt1mmi2+KNR U3fw== 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 g14-v6si1643870pfd.86.2018.09.25.10.22.06; Tue, 25 Sep 2018 10:22:22 -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 S1728137AbeIYX2t (ORCPT + 99 others); Tue, 25 Sep 2018 19:28:49 -0400 Received: from out02.mta.xmission.com ([166.70.13.232]:60823 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726400AbeIYX2s (ORCPT ); Tue, 25 Sep 2018 19:28:48 -0400 Received: from in01.mta.xmission.com ([166.70.13.51]) by out02.mta.xmission.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.87) (envelope-from ) id 1g4r0V-0000Zr-Jn; Tue, 25 Sep 2018 11:20:19 -0600 Received: from [105.184.227.67] (helo=x220.Home) by in01.mta.xmission.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA256:128) (Exim 4.87) (envelope-from ) id 1g4r0U-0001uD-C1; Tue, 25 Sep 2018 11:20:19 -0600 From: "Eric W. Biederman" To: linux-kernel@vger.kernel.org Cc: linux-api@vger.kernel.org, linux-arch@vger.kernel.org, Oleg Nesterov , Linus Torvalds , "Eric W. Biederman" Date: Tue, 25 Sep 2018 19:19:04 +0200 Message-Id: <20180925171906.19683-4-ebiederm@xmission.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <87h8idv6nw.fsf@xmission.com> References: <87h8idv6nw.fsf@xmission.com> X-XM-SPF: eid=1g4r0U-0001uD-C1;;;mid=<20180925171906.19683-4-ebiederm@xmission.com>;;;hst=in01.mta.xmission.com;;;ip=105.184.227.67;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX19ERpqjCZhmsFTJC92C1QflMzMLeh7SunY= X-SA-Exim-Connect-IP: 105.184.227.67 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=4.0 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,TR_Symld_Words,T_TooManySym_01,T_TooManySym_02, XMGappySubj_01,XMNoVowels,XMSubLong autolearn=disabled version=3.4.1 X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 1.5 TR_Symld_Words too many words that have symbols inside * 1.5 XMNoVowels Alpha-numberic number with no vowels * 0.5 XMGappySubj_01 Very gappy subject * 0.7 XMSubLong Long Subject * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.4999] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa07 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_02 5+ unique symbols in subject * 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 283 ms - load_scoreonly_sql: 0.04 (0.0%), signal_user_changed: 2.9 (1.0%), b_tie_ro: 2.0 (0.7%), parse: 1.06 (0.4%), extract_message_metadata: 12 (4.3%), get_uri_detail_list: 2.8 (1.0%), tests_pri_-1000: 6 (1.9%), tests_pri_-950: 1.15 (0.4%), tests_pri_-900: 0.96 (0.3%), tests_pri_-400: 21 (7.4%), check_bayes: 20 (7.0%), b_tokenize: 8 (2.7%), b_tok_get_all: 6 (1.9%), b_comp_prob: 1.66 (0.6%), b_tok_touch_all: 3.1 (1.1%), b_finish: 0.63 (0.2%), tests_pri_0: 229 (81.1%), check_dkim_signature: 0.48 (0.2%), check_dkim_adsp: 2.4 (0.8%), tests_pri_500: 6 (2.0%), rewrite_mail: 0.00 (0.0%) Subject: [REVIEW][PATCH 4/6] signal: Introduce copy_siginfo_from_user and use it's return value 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 In preparation for using a smaller version of siginfo in the kernel introduce copy_siginfo_from_user and use it when siginfo is copied from userspace. Make the pattern for using copy_siginfo_from_user and copy_siginfo_from_user32 to capture the return value and return that value on error. This is a necessary prerequisite for using a smaller siginfo in the kernel than the kernel exports to userspace. Signed-off-by: "Eric W. Biederman" --- include/linux/signal.h | 1 + kernel/ptrace.c | 12 +++++------- kernel/signal.c | 25 ++++++++++++++++--------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/include/linux/signal.h b/include/linux/signal.h index 3d4cd5db30a9..de94c159bfb0 100644 --- a/include/linux/signal.h +++ b/include/linux/signal.h @@ -22,6 +22,7 @@ static inline void clear_siginfo(struct siginfo *info) } int copy_siginfo_to_user(struct siginfo __user *to, const struct siginfo *from); +int copy_siginfo_from_user(struct siginfo *to, const struct siginfo __user *from); enum siginfo_layout { SIL_KILL, diff --git a/kernel/ptrace.c b/kernel/ptrace.c index 45f77a1b9c97..a807ff5cc1a9 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -919,9 +919,8 @@ int ptrace_request(struct task_struct *child, long request, break; case PTRACE_SETSIGINFO: - if (copy_from_user(&siginfo, datavp, sizeof siginfo)) - ret = -EFAULT; - else + ret = copy_siginfo_from_user(&siginfo, datavp); + if (!ret) ret = ptrace_setsiginfo(child, &siginfo); break; @@ -1215,10 +1214,9 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request, break; case PTRACE_SETSIGINFO: - if (copy_siginfo_from_user32( - &siginfo, (struct compat_siginfo __user *) datap)) - ret = -EFAULT; - else + ret = copy_siginfo_from_user32( + &siginfo, (struct compat_siginfo __user *) datap); + if (!ret) ret = ptrace_setsiginfo(child, &siginfo); break; #ifdef CONFIG_HAVE_ARCH_TRACEHOOK diff --git a/kernel/signal.c b/kernel/signal.c index debb485a76db..c0e289e62d77 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -2896,6 +2896,13 @@ int copy_siginfo_to_user(siginfo_t __user *to, const siginfo_t *from) return 0; } +int copy_siginfo_from_user(siginfo_t *to, const siginfo_t __user *from) +{ + if (copy_from_user(to, from, sizeof(struct siginfo))) + return -EFAULT; + return 0; +} + #ifdef CONFIG_COMPAT int copy_siginfo_to_user32(struct compat_siginfo __user *to, const struct siginfo *from) @@ -3323,8 +3330,9 @@ SYSCALL_DEFINE3(rt_sigqueueinfo, pid_t, pid, int, sig, siginfo_t __user *, uinfo) { siginfo_t info; - if (copy_from_user(&info, uinfo, sizeof(siginfo_t))) - return -EFAULT; + int ret = copy_siginfo_from_user(&info, uinfo); + if (unlikely(ret)) + return ret; return do_rt_sigqueueinfo(pid, sig, &info); } @@ -3365,10 +3373,9 @@ SYSCALL_DEFINE4(rt_tgsigqueueinfo, pid_t, tgid, pid_t, pid, int, sig, siginfo_t __user *, uinfo) { siginfo_t info; - - if (copy_from_user(&info, uinfo, sizeof(siginfo_t))) - return -EFAULT; - + int ret = copy_siginfo_from_user(&info, uinfo); + if (unlikely(ret)) + return ret; return do_rt_tgsigqueueinfo(tgid, pid, sig, &info); } @@ -3380,9 +3387,9 @@ COMPAT_SYSCALL_DEFINE4(rt_tgsigqueueinfo, struct compat_siginfo __user *, uinfo) { siginfo_t info; - - if (copy_siginfo_from_user32(&info, uinfo)) - return -EFAULT; + int ret = copy_siginfo_from_user32(&info, uinfo); + if (unlikely(ret)) + return ret; return do_rt_tgsigqueueinfo(tgid, pid, sig, &info); } #endif -- 2.17.1