From patchwork Mon Jan 16 13:23:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Djalal Harouni X-Patchwork-Id: 9518747 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 7894D6020B for ; Mon, 16 Jan 2017 13:24:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E4F428438 for ; Mon, 16 Jan 2017 13:24:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5309528458; Mon, 16 Jan 2017 13:24:07 +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=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 7BD6F28438 for ; Mon, 16 Jan 2017 13:24:06 +0000 (UTC) Received: (qmail 22500 invoked by uid 550); 16 Jan 2017 13:24:04 -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: Reply-To: kernel-hardening@lists.openwall.com Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 22433 invoked from network); 16 Jan 2017 13:24: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 :mime-version:content-transfer-encoding; bh=xGnjjKDeqep0mRBDEVPGo4mljFFMwCWwV4lVG8SL3Ks=; b=OgosR9jnyXMHEMZkq3rseTcZ5ywokUNGPr453KkYn1R+t2XAfE0ky3sC1QUGrYkZNk QpvKzVRl3Mp/wpkv0q8q0LqhN4DJl2izrddzyiPFRFDERTXPV15lRgyIijbP7fzK2ztC nTOswArCjqedONXP1sng2olnWq5rgScNroM1kuLRaOLHGEkY/uITiBnYpTx4TI/9NJ98 bBCNzYrURfvxpZNYDUF2Myef+9XqL7TZqXqkeS1HhS9iZLZdKj2VIx4JaafLDfZmqaOR 012gG7JwEp9hvlyaoEpf53EH2igSbCdlQL9F9d2Fyjmj66XzZarKTzwLdvaBrraFkuA9 a5Zg== 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:mime-version:content-transfer-encoding; bh=xGnjjKDeqep0mRBDEVPGo4mljFFMwCWwV4lVG8SL3Ks=; b=Oxl2pzzKHlGDXMVn335TTZYJsb2VdGsxvPte/joJxw7+dzcqzUceJuj9iFSJgub3sv YbXlF1Y8snVIM9DNo1dQxSARUkF9FRNMK/LaVGEPc7mQqW/nAybSEeAkCOYubQ3s4NRM NKzx0HbpOeXqXdpYcSf+mXm/aPgaJqCQncWYdpP/UAGNlCl3nohYJQST/owLK5OaXLzS /BS75rJMP3LSJq3ttqzx3u04rzVJzMdaWPD9fHbjcA86f5g3yFoclk1ADyNCY7LweQ4t 2/6jmFLz9rWbc57zvgGMTcfZqQrG5sQQaNtgAt68L9rGeLDa1Y/Njvp75VkoLpaIOtcy /71w== X-Gm-Message-State: AIkVDXLR5Ju18CJaNDjSnsDBaPOLvBMQwRNIb/zyCP/JXcrkX7cNNphP1opCKrlbyLWC+g== X-Received: by 10.28.184.198 with SMTP id i189mr11354414wmf.26.1484573030414; Mon, 16 Jan 2017 05:23:50 -0800 (PST) From: Djalal Harouni X-Google-Original-From: Djalal Harouni To: linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com Cc: Andrew Morton , Kees Cook , Lafcadio Wluiki , Djalal Harouni Date: Mon, 16 Jan 2017 14:23:03 +0100 Message-Id: <1484572984-13388-2-git-send-email-djalal@gmail.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1484572984-13388-1-git-send-email-djalal@gmail.com> References: <1484572984-13388-1-git-send-email-djalal@gmail.com> MIME-Version: 1.0 Subject: [kernel-hardening] [PATCH v4 1/2] procfs: use an enum for possible hidepid values X-Virus-Scanned: ClamAV using ClamSMTP From: Lafcadio Wluiki Previously, the hidepid parameter was checked by comparing literal integers 0, 1, 2. Let's add a proper enum for this, to make the checking more expressive: 0 → HIDEPID_OFF 1 → HIDEPID_NO_ACCESS 2 → HIDEPID_INVISIBLE This changes the internal labelling only, the userspace-facing interface remains unmodified, and still works with literal integers 0, 1, 2. No functional changes. Acked-by: Kees Cook Acked-by: Djalal Harouni Signed-off-by: Lafcadio Wluiki --- fs/proc/base.c | 8 ++++---- fs/proc/inode.c | 2 +- fs/proc/root.c | 3 ++- include/linux/pid_namespace.h | 6 ++++++ 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index 8e7e61b..cd8dd15 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -729,11 +729,11 @@ static int proc_pid_permission(struct inode *inode, int mask) task = get_proc_task(inode); if (!task) return -ESRCH; - has_perms = has_pid_permissions(pid, task, 1); + has_perms = has_pid_permissions(pid, task, HIDEPID_NO_ACCESS); put_task_struct(task); if (!has_perms) { - if (pid->hide_pid == 2) { + if (pid->hide_pid == HIDEPID_INVISIBLE) { /* * Let's make getdents(), stat(), and open() * consistent with each other. If a process @@ -1725,7 +1725,7 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) stat->gid = GLOBAL_ROOT_GID; task = pid_task(proc_pid(inode), PIDTYPE_PID); if (task) { - if (!has_pid_permissions(pid, task, 2)) { + if (!has_pid_permissions(pid, task, HIDEPID_INVISIBLE)) { rcu_read_unlock(); /* * This doesn't prevent learning whether PID exists, @@ -3179,7 +3179,7 @@ int proc_pid_readdir(struct file *file, struct dir_context *ctx) iter.tgid += 1, iter = next_tgid(ns, iter)) { char name[PROC_NUMBUF]; int len; - if (!has_pid_permissions(ns, iter.task, 2)) + if (!has_pid_permissions(ns, iter.task, HIDEPID_INVISIBLE)) continue; len = snprintf(name, sizeof(name), "%d", iter.tgid); diff --git a/fs/proc/inode.c b/fs/proc/inode.c index 842a5ff..5d9bafb 100644 --- a/fs/proc/inode.c +++ b/fs/proc/inode.c @@ -106,7 +106,7 @@ static int proc_show_options(struct seq_file *seq, struct dentry *root) if (!gid_eq(pid->pid_gid, GLOBAL_ROOT_GID)) seq_printf(seq, ",gid=%u", from_kgid_munged(&init_user_ns, pid->pid_gid)); - if (pid->hide_pid != 0) + if (pid->hide_pid != HIDEPID_OFF) seq_printf(seq, ",hidepid=%u", pid->hide_pid); return 0; diff --git a/fs/proc/root.c b/fs/proc/root.c index 1988440..b90da88 100644 --- a/fs/proc/root.c +++ b/fs/proc/root.c @@ -58,7 +58,8 @@ int proc_parse_options(char *options, struct pid_namespace *pid) case Opt_hidepid: if (match_int(&args[0], &option)) return 0; - if (option < 0 || option > 2) { + if (option < HIDEPID_OFF || + option > HIDEPID_INVISIBLE) { pr_err("proc: hidepid value must be between 0 and 2.\n"); return 0; } diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h index 34cce96..c2a989d 100644 --- a/include/linux/pid_namespace.h +++ b/include/linux/pid_namespace.h @@ -21,6 +21,12 @@ struct pidmap { struct fs_pin; +enum { /* definitions for pid_namespace's hide_pid field */ + HIDEPID_OFF = 0, + HIDEPID_NO_ACCESS = 1, + HIDEPID_INVISIBLE = 2, +}; + struct pid_namespace { struct kref kref; struct pidmap pidmap[PIDMAP_ENTRIES];