Received: by 10.192.165.148 with SMTP id m20csp793631imm; Wed, 2 May 2018 08:54:47 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrtS7FRk5uNNwXPoWBzGd7StE6BccTKlK07GMWiIhom46ji6AoyReAFtymIOWU4cu1XKN8k X-Received: by 2002:a65:50cc:: with SMTP id s12-v6mr16866426pgp.313.1525276487524; Wed, 02 May 2018 08:54:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525276487; cv=none; d=google.com; s=arc-20160816; b=mDDvgqhUKLpMgxOuPzDxjm96eyWKwx3C5RutIpCxAhZ2F5bUMcX46UKUBOPVzwCFqU K/MEcRJsvlxGvGj3//IvMklXWaVKYtGoTuUxiP7/k6SWqTMohjN21Eo8IyQViFSARKG/ +9V0YcPfz4elBiD+LCqBN/AczO2sGnHZa3jmEUCNKHgNhxjK8opcGPabpZkb9cTQdHF8 QiDDoylMkkhliaR0PyaCuvaa6lOkj/4j2SnnOm8XoCWwg8HQMJOcMpGUKOeo4zbOQ1uW +lMJthvzxc0akjQEzYvz2DZTAzN/HhZJekQSXPeiyQ08iF+73D2wt1ss1uabZ/yWBVA5 ofGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=lqTlYlQm9bNz/MCEPbQsTDxv4J4GRd7A5u1Wd3N9uvM=; b=I2t2WFm1BJjIJLSba1JBS84ejCthF3RcbnRkr5HF9GuBXa5pA7kSnY+C6f7ne/Ptgz BykqgiAzYvphKPE98MzHvJZmO+kDuH8nmPip3sXfBDGU10RWwm6bN2c+IvNhnB0rCmFw gp69ZLfN9o3sDslIPkXlYawCzhtEwBU6yIU4Bj7gRYoxmEI1MGsxyRlnmh+Sc77NNqfP 0Y+/xYvptClHuklc+cABED6Ip74e61jkYQCoiZkcORfqJYshGQ5shgg2WOsTOTZiMvv3 lGewmKybsYtafB8d5wM7+c/hxe7fVDUgUxNnK50wAbqsp//GM2S/pYi4MoxtERP73x3G p17w== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d25-v6si10068711plj.344.2018.05.02.08.54.33; Wed, 02 May 2018 08:54:47 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751820AbeEBPyR (ORCPT + 99 others); Wed, 2 May 2018 11:54:17 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:54846 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751100AbeEBPyL (ORCPT ); Wed, 2 May 2018 11:54:11 -0400 Received: from 2.general.tyhicks.us.vpn ([10.172.64.53] helo=sec.l.tihix.com) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1fDu54-0007uo-2l; Wed, 02 May 2018 15:54:10 +0000 From: Tyler Hicks To: linux-kernel@vger.kernel.org Cc: Kees Cook , Andy Lutomirski , Will Drewry , Paul Moore , Eric Paris , Steve Grubb , Jonathan Corbet , linux-audit@redhat.com, linux-security-module@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH v2 1/4] seccomp: Separate read and write code for actions_logged sysctl Date: Wed, 2 May 2018 15:53:17 +0000 Message-Id: <1525276400-7161-2-git-send-email-tyhicks@canonical.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1525276400-7161-1-git-send-email-tyhicks@canonical.com> References: <1525276400-7161-1-git-send-email-tyhicks@canonical.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Break the read and write paths of the kernel.seccomp.actions_logged sysctl into separate functions to maintain readability. An upcoming change will need to audit writes, but not reads, of this sysctl which would introduce too many conditional code paths on whether or not the 'write' parameter evaluates to true. Signed-off-by: Tyler Hicks --- kernel/seccomp.c | 60 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/kernel/seccomp.c b/kernel/seccomp.c index dc77548..f4afe67 100644 --- a/kernel/seccomp.c +++ b/kernel/seccomp.c @@ -1199,48 +1199,64 @@ static bool seccomp_actions_logged_from_names(u32 *actions_logged, char *names) return true; } -static int seccomp_actions_logged_handler(struct ctl_table *ro_table, int write, - void __user *buffer, size_t *lenp, - loff_t *ppos) +static int read_actions_logged(struct ctl_table *ro_table, void __user *buffer, + size_t *lenp, loff_t *ppos) { char names[sizeof(seccomp_actions_avail)]; struct ctl_table table; + + memset(names, 0, sizeof(names)); + + if (!seccomp_names_from_actions_logged(names, sizeof(names), + seccomp_actions_logged)) + return -EINVAL; + + table = *ro_table; + table.data = names; + table.maxlen = sizeof(names); + return proc_dostring(&table, 0, buffer, lenp, ppos); +} + +static int write_actions_logged(struct ctl_table *ro_table, void __user *buffer, + size_t *lenp, loff_t *ppos) +{ + char names[sizeof(seccomp_actions_avail)]; + struct ctl_table table; + u32 actions_logged; int ret; - if (write && !capable(CAP_SYS_ADMIN)) + if (!capable(CAP_SYS_ADMIN)) return -EPERM; memset(names, 0, sizeof(names)); - if (!write) { - if (!seccomp_names_from_actions_logged(names, sizeof(names), - seccomp_actions_logged)) - return -EINVAL; - } - table = *ro_table; table.data = names; table.maxlen = sizeof(names); - ret = proc_dostring(&table, write, buffer, lenp, ppos); + ret = proc_dostring(&table, 1, buffer, lenp, ppos); if (ret) return ret; - if (write) { - u32 actions_logged; - - if (!seccomp_actions_logged_from_names(&actions_logged, - table.data)) - return -EINVAL; - - if (actions_logged & SECCOMP_LOG_ALLOW) - return -EINVAL; + if (!seccomp_actions_logged_from_names(&actions_logged, table.data)) + return -EINVAL; - seccomp_actions_logged = actions_logged; - } + if (actions_logged & SECCOMP_LOG_ALLOW) + return -EINVAL; + seccomp_actions_logged = actions_logged; return 0; } +static int seccomp_actions_logged_handler(struct ctl_table *ro_table, int write, + void __user *buffer, size_t *lenp, + loff_t *ppos) +{ + if (write) + return write_actions_logged(ro_table, buffer, lenp, ppos); + else + return read_actions_logged(ro_table, buffer, lenp, ppos); +} + static struct ctl_path seccomp_sysctl_path[] = { { .procname = "kernel", }, { .procname = "seccomp", }, -- 2.7.4