From patchwork Mon Sep 11 19:50:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Salvatore Mesoraca X-Patchwork-Id: 9948019 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 0E878602C9 for ; Mon, 11 Sep 2017 19:53:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07D5E28D31 for ; Mon, 11 Sep 2017 19:53:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F0C6C28D34; Mon, 11 Sep 2017 19:53:16 +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=-2.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, GAPPY_SUBJECT, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 2803F28D31 for ; Mon, 11 Sep 2017 19:53:15 +0000 (UTC) Received: (qmail 3349 invoked by uid 550); 11 Sep 2017 19:52:06 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 3144 invoked from network); 11 Sep 2017 19:52:01 -0000 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=mayClebeHm8dX2GGPLIz5GwvNlasb/xC7YDc5zKoWqg=; b=IaXBQFuarz0U74ZicabTng7C+g0XzxFreVE45KG71zJFML6hPSb+qSlI+lsywF3P3a ictC/MK7Q+i57nj6/0YSyqk0b4Ti1aLYzfOFJx6ExJSzHmVUTjbhFb53RGPVnQXTEEis l7oqk8WNbtKRdoifSKq+sIq3t4C5whXhOAlpJAdYQP7sj8hoTN++OTNh2xJBE4613KVb XJQlNW52hPYvR6XdG73fzdyZMmysgmL9mixuK69vgxeCfucrv8MVxL/YMzIifgD9jNzP ySBqQcH3LdTK0xkiWplVwk/a22+VaPucOmz3b8gkCqbDGCYIGFo+m8ZUjLmpQgC3uUlJ kA8Q== 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=mayClebeHm8dX2GGPLIz5GwvNlasb/xC7YDc5zKoWqg=; b=fq0OqGQT+6vo1u9DVdtvsQuqEsH4VwQz1rlknKGqBWTwoQ5mpgpvXgZ9ugp3W/pXyp sxBq9vyJ3Yo3Eb2hmRJMpLIBbJRjmlVxNlT1VGgKwyzpD79ZAi9nkGSmRDdwfAjgpRRf L6KwKyu1+J0iowxs1GTC7sf7uBH24yVhF5vTCRPqxLvxEKP+mG30liugEZASmAszN4HV F1hWLZ157VFRUWkPw6KfpFViEHCUh0fNd19fpwlhqWW75PYWoNxuyf1DKT1qo85vNpYy xIis1D3Ry7TT0JJvPqwnuD3akZvuIjSB8WDECwXSvMsqpsEMpH3UbE9ycXKL9kPG4cKf hozQ== X-Gm-Message-State: AHPjjUjKP7+Gi6ZNHqaRFNIii7f1Gw374Y4Xe69carhdp+HJy3LB6AxS hlOlbIheeH0rExZaIciYxqk= X-Google-Smtp-Source: AOwi7QC1eoLB0pYzSTAIU8dSM/T7NC6RIErzkYwTzIS2O9ijYxCdNMxsV1Y7vgm8Vd2LYy7AY1ZQ9Q== X-Received: by 10.28.91.73 with SMTP id p70mr10140080wmb.13.1505159509895; Mon, 11 Sep 2017 12:51:49 -0700 (PDT) From: Salvatore Mesoraca To: linux-kernel@vger.kernel.org Cc: linux-security-module@vger.kernel.org, kernel-hardening@lists.openwall.com, Salvatore Mesoraca , Brad Spengler , PaX Team , Casey Schaufler , Kees Cook , James Morris , "Serge E. Hallyn" Date: Mon, 11 Sep 2017 21:50:26 +0200 Message-Id: <1505159427-11747-9-git-send-email-s.mesoraca16@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505159427-11747-1-git-send-email-s.mesoraca16@gmail.com> References: <1505159427-11747-1-git-send-email-s.mesoraca16@gmail.com> Subject: [kernel-hardening] [RFC v3 8/9] Allowing for stacking procattr support in S.A.R.A. X-Virus-Scanned: ClamAV using ClamSMTP This allow S.A.R.A. to use the procattr interface without interfering with other LSMs. This part should be reimplemented as soon as upstream procattr stacking support is available. Signed-off-by: Salvatore Mesoraca --- fs/proc/base.c | 38 ++++++++++++++++++++++++++++++++++++++ security/security.c | 20 ++++++++++++++++++-- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index e5d89a0..3b10452 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -2559,6 +2559,40 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf, .llseek = generic_file_llseek, }; +#ifdef CONFIG_SECURITY_SARA +static const struct pid_entry sara_attr_dir_stuff[] = { + REG("wxprot", 0666, proc_pid_attr_operations), +}; + +static int proc_sara_attr_dir_readdir(struct file *file, + struct dir_context *ctx) +{ + return proc_pident_readdir(file, ctx, + sara_attr_dir_stuff, + ARRAY_SIZE(sara_attr_dir_stuff)); +} + +static const struct file_operations proc_sara_attr_dir_ops = { + .read = generic_read_dir, + .iterate_shared = proc_sara_attr_dir_readdir, + .llseek = generic_file_llseek, +}; + +static struct dentry *proc_sara_attr_dir_lookup(struct inode *dir, + struct dentry *dentry, unsigned int flags) +{ + return proc_pident_lookup(dir, dentry, + sara_attr_dir_stuff, + ARRAY_SIZE(sara_attr_dir_stuff)); +}; + +static const struct inode_operations proc_sara_attr_dir_inode_ops = { + .lookup = proc_sara_attr_dir_lookup, + .getattr = pid_getattr, + .setattr = proc_setattr, +}; +#endif /* CONFIG_SECURITY_SARA */ + static const struct pid_entry attr_dir_stuff[] = { REG("current", S_IRUGO|S_IWUGO, proc_pid_attr_operations), REG("prev", S_IRUGO, proc_pid_attr_operations), @@ -2566,6 +2600,10 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf, REG("fscreate", S_IRUGO|S_IWUGO, proc_pid_attr_operations), REG("keycreate", S_IRUGO|S_IWUGO, proc_pid_attr_operations), REG("sockcreate", S_IRUGO|S_IWUGO, proc_pid_attr_operations), +#ifdef CONFIG_SECURITY_SARA + DIR("sara", 0555, proc_sara_attr_dir_inode_ops, + proc_sara_attr_dir_ops), +#endif }; static int proc_attr_dir_readdir(struct file *file, struct dir_context *ctx) diff --git a/security/security.c b/security/security.c index 4f50dc5..a27cfa8 100644 --- a/security/security.c +++ b/security/security.c @@ -1277,12 +1277,28 @@ void security_d_instantiate(struct dentry *dentry, struct inode *inode) int security_getprocattr(struct task_struct *p, char *name, char **value) { - return call_int_hook(getprocattr, -EINVAL, p, name, value); + struct security_hook_list *hp; + int rc; + + list_for_each_entry(hp, &security_hook_heads.getprocattr, list) { + rc = hp->hook.getprocattr(p, name, value); + if (rc != -EINVAL) + return rc; + } + return -EINVAL; } int security_setprocattr(const char *name, void *value, size_t size) { - return call_int_hook(setprocattr, -EINVAL, name, value, size); + struct security_hook_list *hp; + int rc; + + list_for_each_entry(hp, &security_hook_heads.setprocattr, list) { + rc = hp->hook.setprocattr(name, value, size); + if (rc != -EINVAL) + return rc; + } + return -EINVAL; } int security_netlink_send(struct sock *sk, struct sk_buff *skb)