From patchwork Mon Jun 19 06:45:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepa Dinamani X-Patchwork-Id: 9795271 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D8BAD6020B for ; Mon, 19 Jun 2017 06:47:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C24F327E5A for ; Mon, 19 Jun 2017 06:47:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B768627EE2; Mon, 19 Jun 2017 06:47:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 38EB327E5A for ; Mon, 19 Jun 2017 06:47:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753343AbdFSGpr (ORCPT ); Mon, 19 Jun 2017 02:45:47 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:35004 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753686AbdFSGpp (ORCPT ); Mon, 19 Jun 2017 02:45:45 -0400 Received: by mail-pg0-f66.google.com with SMTP id f127so14284587pgc.2; Sun, 18 Jun 2017 23:45:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mWlRYhEs77ZE1u2azgsaYqeejfYBaDLekSFH772vVX4=; b=HT0x/nAlptcB7087fKKrMtAWoSMtZcIfSNWqaezm29mzeX9edMcnMabO2dz+5XDK+u rwDnM9mn9/bI9OEweyooh6cD1GphSNUaNOsLtEcTTGojXrRl+0PiCDQSu7kE689XVpCP AdrUC8E9m0+rAttDriQKqdMOp5QRKuYOOn1wlP6/O0T45RMNrSogbYVZn/gNfNO4sJN4 /qdaQteHy1wrnovdN5OHcbOMC5koQPhZuWsedOnv+4hvRUiPVgZg9M2trMRVgsyk4/es G7j244Toy4SFkRR/MZr0KzDFCT8lhxo+mZwlNRcO5g/RZqru5A9TmJprz6MY6WQJSuEN 7qYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mWlRYhEs77ZE1u2azgsaYqeejfYBaDLekSFH772vVX4=; b=npMmSnsVAPtxkHDZhKnE+GIrQ6cKntFnLVa8zyZNr8RIurfIJFx8YLD1kxkJTviJlM 0xkZuHqfk9okVvtC0K+sWJIRGUWIIE18nRxYpSSsTvECU2UmUqcyt7C7Z8XNBe91MNBs QlwTcRdH32QmwY6R3P6tHSStUKcHN7jBog5hefbNa6t7nkMWJCMZ30lf+TR3I/80ONjw inN1LEw3MxuksgTDsFstai2hasudgw+O6m0NUlovr2sLW5+n3BPHb5gNuNegssmi0QoY dTzmQ1daHPR8krwAdgqQltc1VNq0lgsyt4R2JgCybAU4wgAIwZ544mBsXrNxGGV2XpR/ vRLQ== X-Gm-Message-State: AKS2vOzsgHTZkFxfJ0vmtxfxfAMc6Uz65eNUEuDCmO5L8iwzW8Sf0h7z owU8QMBIzCbQR/Av X-Received: by 10.98.103.134 with SMTP id t6mr23394975pfj.83.1497854744462; Sun, 18 Jun 2017 23:45:44 -0700 (PDT) Received: from localhost.localdomain ([2601:647:5000:6620:ecf7:aabb:b31b:424d]) by smtp.gmail.com with ESMTPSA id o66sm19620318pga.64.2017.06.18.23.45.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 18 Jun 2017 23:45:44 -0700 (PDT) From: Deepa Dinamani To: tglx@linutronix.de, viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org Cc: john.stultz@linaro.org, nicolas.pitre@linaro.org, arnd@arndb.de, y2038@lists.linaro.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 3/8] kernel: compat: Move clock and timer compat syscalls Date: Sun, 18 Jun 2017 23:45:10 -0700 Message-Id: <20170619064515.922-4-deepa.kernel@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170619064515.922-1-deepa.kernel@gmail.com> References: <20170619064515.922-1-deepa.kernel@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Move the compat syscall handling to the files that handle the native syscalls. The move helps for code reusability by helping same functions be used in both compat and native syscall handling paths. In this series, this servers as a preparatory patch to eliminate the use of set_fs()/get_fs() in the compat syscall path. Note that the clock compat syscalls have to be moved twice, once into each file: posix_timers.c and posix-stubs.c. Signed-off-by: Deepa Dinamani --- kernel/compat.c | 91 --------------------------------------------- kernel/time/posix-stubs.c | 55 +++++++++++++++++++++++++++ kernel/time/posix-timers.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+), 91 deletions(-) diff --git a/kernel/compat.c b/kernel/compat.c index 89d10cf47e9c..d6559c0c69b0 100644 --- a/kernel/compat.c +++ b/kernel/compat.c @@ -675,80 +675,6 @@ COMPAT_SYSCALL_DEFINE3(timer_create, clockid_t, which_clock, return sys_timer_create(which_clock, event, created_timer_id); } -COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags, - struct compat_itimerspec __user *, new, - struct compat_itimerspec __user *, old) -{ - long err; - mm_segment_t oldfs; - struct itimerspec newts, oldts; - - if (!new) - return -EINVAL; - if (get_compat_itimerspec(&newts, new)) - return -EFAULT; - oldfs = get_fs(); - set_fs(KERNEL_DS); - err = sys_timer_settime(timer_id, flags, - (struct itimerspec __user *) &newts, - (struct itimerspec __user *) &oldts); - set_fs(oldfs); - if (!err && old && put_compat_itimerspec(old, &oldts)) - return -EFAULT; - return err; -} - -COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id, - struct compat_itimerspec __user *, setting) -{ - long err; - mm_segment_t oldfs; - struct itimerspec ts; - - oldfs = get_fs(); - set_fs(KERNEL_DS); - err = sys_timer_gettime(timer_id, - (struct itimerspec __user *) &ts); - set_fs(oldfs); - if (!err && put_compat_itimerspec(setting, &ts)) - return -EFAULT; - return err; -} - -COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock, - struct compat_timespec __user *, tp) -{ - long err; - mm_segment_t oldfs; - struct timespec ts; - - if (compat_get_timespec(&ts, tp)) - return -EFAULT; - oldfs = get_fs(); - set_fs(KERNEL_DS); - err = sys_clock_settime(which_clock, - (struct timespec __user *) &ts); - set_fs(oldfs); - return err; -} - -COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock, - struct compat_timespec __user *, tp) -{ - long err; - mm_segment_t oldfs; - struct timespec ts; - - oldfs = get_fs(); - set_fs(KERNEL_DS); - err = sys_clock_gettime(which_clock, - (struct timespec __user *) &ts); - set_fs(oldfs); - if (!err && compat_put_timespec(&ts, tp)) - return -EFAULT; - return err; -} - COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock, struct compat_timex __user *, utp) { @@ -772,23 +698,6 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock, return ret; } -COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock, - struct compat_timespec __user *, tp) -{ - long err; - mm_segment_t oldfs; - struct timespec ts; - - oldfs = get_fs(); - set_fs(KERNEL_DS); - err = sys_clock_getres(which_clock, - (struct timespec __user *) &ts); - set_fs(oldfs); - if (!err && tp && compat_put_timespec(&ts, tp)) - return -EFAULT; - return err; -} - /* * We currently only need the following fields from the sigevent * structure: sigev_value, sigev_signo, sig_notify and (sometimes diff --git a/kernel/time/posix-stubs.c b/kernel/time/posix-stubs.c index 3031a28921ba..cd1b9a2e2618 100644 --- a/kernel/time/posix-stubs.c +++ b/kernel/time/posix-stubs.c @@ -125,6 +125,61 @@ SYSCALL_DEFINE4(clock_nanosleep, const clockid_t, which_clock, int, flags, } #ifdef CONFIG_COMPAT +#define COMPAT_SYS_NI(name) SYSCALL_ALIAS(compat_sys_##name, sys_ni_posix_timers) +COMPAT_SYS_NI(timer_gettime); +COMPAT_SYS_NI(timer_settime); + +COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock, + struct compat_timespec __user *, tp) +{ + long err; + mm_segment_t oldfs; + struct timespec ts; + + if (compat_get_timespec(&ts, tp)) + return -EFAULT; + oldfs = get_fs(); + set_fs(KERNEL_DS); + err = sys_clock_settime(which_clock, + (struct timespec __user *) &ts); + set_fs(oldfs); + return err; +} + +COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock, + struct compat_timespec __user *, tp) +{ + long err; + mm_segment_t oldfs; + struct timespec ts; + + oldfs = get_fs(); + set_fs(KERNEL_DS); + err = sys_clock_gettime(which_clock, + (struct timespec __user *) &ts); + set_fs(oldfs); + if (!err && compat_put_timespec(&ts, tp)) + return -EFAULT; + return err; +} + +COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock, + struct compat_timespec __user *, tp) +{ + long err; + mm_segment_t oldfs; + struct timespec ts; + + oldfs = get_fs(); + set_fs(KERNEL_DS); + err = sys_clock_getres(which_clock, + (struct timespec __user *) &ts); + set_fs(oldfs); + if (!err && tp && compat_put_timespec(&ts, tp)) + return -EFAULT; + return err; +} + long clock_nanosleep_restart(struct restart_block *restart_block) { return hrtimer_nanosleep_restart(restart_block); diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c index cf32adccd062..009a9145d64d 100644 --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -1233,4 +1233,96 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags, } return err; } + +COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags, + struct compat_itimerspec __user *, new, + struct compat_itimerspec __user *, old) +{ + long err; + mm_segment_t oldfs; + struct itimerspec newts, oldts; + + if (!new) + return -EINVAL; + if (get_compat_itimerspec(&newts, new)) + return -EFAULT; + oldfs = get_fs(); + set_fs(KERNEL_DS); + err = sys_timer_settime(timer_id, flags, + (struct itimerspec __user *) &newts, + (struct itimerspec __user *) &oldts); + set_fs(oldfs); + if (!err && old && put_compat_itimerspec(old, &oldts)) + return -EFAULT; + return err; +} + +COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id, + struct compat_itimerspec __user *, setting) +{ + long err; + mm_segment_t oldfs; + struct itimerspec ts; + + oldfs = get_fs(); + set_fs(KERNEL_DS); + err = sys_timer_gettime(timer_id, + (struct itimerspec __user *) &ts); + set_fs(oldfs); + if (!err && put_compat_itimerspec(setting, &ts)) + return -EFAULT; + return err; +} + +COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock, + struct compat_timespec __user *, tp) +{ + long err; + mm_segment_t oldfs; + struct timespec ts; + + if (compat_get_timespec(&ts, tp)) + return -EFAULT; + oldfs = get_fs(); + set_fs(KERNEL_DS); + err = sys_clock_settime(which_clock, + (struct timespec __user *) &ts); + set_fs(oldfs); + return err; +} + +COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock, + struct compat_timespec __user *, tp) +{ + long err; + mm_segment_t oldfs; + struct timespec ts; + + oldfs = get_fs(); + set_fs(KERNEL_DS); + err = sys_clock_gettime(which_clock, + (struct timespec __user *) &ts); + set_fs(oldfs); + if (!err && compat_put_timespec(&ts, tp)) + return -EFAULT; + return err; +} + +COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock, + struct compat_timespec __user *, tp) +{ + long err; + mm_segment_t oldfs; + struct timespec ts; + + oldfs = get_fs(); + set_fs(KERNEL_DS); + err = sys_clock_getres(which_clock, + (struct timespec __user *) &ts); + set_fs(oldfs); + if (!err && tp && compat_put_timespec(&ts, tp)) + return -EFAULT; + return err; +} + #endif