From patchwork Tue Nov 21 18:26:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Salvatore Mesoraca X-Patchwork-Id: 10068709 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 5A1206022E for ; Tue, 21 Nov 2017 18:28:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 50A96283CA for ; Tue, 21 Nov 2017 18:28:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4556D298B8; Tue, 21 Nov 2017 18:28:21 +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 72A81283CA for ; Tue, 21 Nov 2017 18:28:19 +0000 (UTC) Received: (qmail 32222 invoked by uid 550); 21 Nov 2017 18:26:59 -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 32128 invoked from network); 21 Nov 2017 18:26:57 -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=IpZhtUKQ+8pX3ph0ocepjr7bLfaXN+cOm0v5k4ukc/M=; b=q0jJcBuOxotyKg0jxTCMqEIMSyBTUEXu6IhTfh1r5zcpZUOkwNak+THDKG0/cltdgX OClkyvscyDAOBY/iJC4e72mmrXxVgNS2tpCCLU/jzEp8eTOv1u0MEftjGBnbL5Nj9zmr foQPvn3lB4Gq17pcBKHnPy6nq+UYZZ79Wp5BBQySq2wsmNh+lG3aWONB70d0+ZIVB8Te QRDaJL+sCGH8tfc4BSlCq4H3jP6OulDEi1UMpnQQv8q98x9mxhHkzCgzZSaoG6bDoMc/ JopYji/uB/PR53zPqNO6V4pyHBG9wiI2PkAXI+nveovTl71G1YoyRk1okYHBu3sH3Nq6 9q+w== 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=IpZhtUKQ+8pX3ph0ocepjr7bLfaXN+cOm0v5k4ukc/M=; b=fte+GpZoYimADvzEluRbU/a1dNN73LR+lK1D0Gnq808gtUyaIdsnW8W56kSh5B8ZzH zMffmhbbCyv9pcP+xJftji502PTqMkGRdKhPgbDxxgzp9nzuVhTVcwI2SIf8rBPXQmNV EHf9OWVI1ugn4vY1ifDXhhQEj8oxPZssnhXSFiw07FO36FjMPTRAsD+4EAuAiBCFrtF2 Zk8Jim4G4dpxkayfRGHjeOaYh+vnga3PGM2HfZG8rudiprTFHhdYx8ggicKarS3H6NNu sQj18ue7PqpiXEzpPn9lC9uzvlZqvkfplHaRwg9TcP/bpUODb88dvUc+sHl9prUfvhxs fsGQ== X-Gm-Message-State: AJaThX6mcmysrkkoWyD7QspK3LXytK7TN2O4ZrkUcna2tK1fDTE6yAI1 zIwn4/K7Sam6EYfAUKS31Jc= X-Google-Smtp-Source: AGs4zMaMhmQcDu7HmL6ZfdTvNpiCYTfYg4RTSBGlU1kc1LjO+B6zMTyrK8X93qMhTxytnmzoJC1J1A== X-Received: by 10.28.6.2 with SMTP id 2mr1952196wmg.37.1511288806591; Tue, 21 Nov 2017 10:26:46 -0800 (PST) From: Salvatore Mesoraca To: linux-kernel@vger.kernel.org Cc: linux-security-module@vger.kernel.org, kernel-hardening@lists.openwall.com, linux-mm@kvack.org, Salvatore Mesoraca , Alexander Viro , Brad Spengler , Casey Schaufler , Christoph Hellwig , James Morris , Jann Horn , Kees Cook , PaX Team , Thomas Gleixner , "Serge E. Hallyn" Date: Tue, 21 Nov 2017 19:26:10 +0100 Message-Id: <1511288772-19308-9-git-send-email-s.mesoraca16@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1511288772-19308-1-git-send-email-s.mesoraca16@gmail.com> References: <1511288772-19308-1-git-send-email-s.mesoraca16@gmail.com> Subject: [kernel-hardening] [RFC v4 08/10] 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 9d357b2..a8a4164 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -2560,6 +2560,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), @@ -2567,6 +2601,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 21cd07e..2d00c5e 100644 --- a/security/security.c +++ b/security/security.c @@ -1273,12 +1273,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)