Received: by 10.213.65.68 with SMTP id h4csp109368imn; Fri, 30 Mar 2018 01:52:14 -0700 (PDT) X-Google-Smtp-Source: AIpwx495IbgE7/AJj2BM9YCncAEqXz4eaxatCxM7OhYuoB40t92Ad0wMLYjgstglsszgS9ndRZ2g X-Received: by 10.98.19.132 with SMTP id 4mr9070737pft.87.1522399934507; Fri, 30 Mar 2018 01:52:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522399934; cv=none; d=google.com; s=arc-20160816; b=V+1vNMbbT7+iVQvU//A2t4kCVXjonkGg2tzqrKELndDVwIRmMWa5MSA9BZ1MOuf37K xXbDJMXzNfKWxsQ+ul9NKS9oYVJV0roo4ffkAbXb7FqY1O+yUcpTQugs+orrB455UCxc BSh2/XYBwOKsojsBt2/J7WfAAS4PAyHS3JZhS0NY9upjMmuwPgIdJgpe8e40FFCbD4Yb UvRRUIX35j66rlwEgptUdUlzp28zCuH2t6pl9vs7AgvyRMlKXS2pwb/lNEjtnU9w3x1t 9dbexBt18ZtSf46lAjwoeqgo4h/5TXynnB9Axz0nz+6g7/6Ejd7jQS+GC2uzOtnL3TYI xNuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :content-transfer-encoding:arc-authentication-results; bh=553VMceGDaxKKL6KML4hEouPPdg7+HbQyYrpKn8xh7I=; b=nhSfvG+vXm3PnTVPi5ixvUuBDd84guy5DUR+X9eBcR6rnD+8St/P2yx2IVNxSaJM67 HTbKblu+v8zg5yKXQLYY74B5y3YM44ZrXpxmQDfULglCR4lzq6Yrtis1Tch1B+aP2MC2 QG5pmvqvotY65ywhgGjdE3f1e/ew530jhIMcG9vnTTAOZwbRQ7O7RM2FzL861KgGEOxy yzxrbT6bof1rmCMWS2CAaOT1C73HQW118CijyMYinBkyNqVItniX4+KFfbNXjwLFYxEs 3vCg4B/UYUVBMth+NzZHrgszn2a6ma5/asfXhRmz06bSdDIBNEGL/fPigcvu+bD7wGNi XsjQ== 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=toshiba.co.jp Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y12-v6si8111376pln.298.2018.03.30.01.52.00; Fri, 30 Mar 2018 01:52:14 -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=toshiba.co.jp Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751252AbeC3Iup (ORCPT + 99 others); Fri, 30 Mar 2018 04:50:45 -0400 Received: from mo-csw-fb1515.securemx.jp ([210.130.202.171]:54274 "EHLO mo-csw-fb.securemx.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750764AbeC3Ium (ORCPT ); Fri, 30 Mar 2018 04:50:42 -0400 Received: by mo-csw-fb.securemx.jp (mx-mo-csw-fb1515) id w2U8V8Vc006734; Fri, 30 Mar 2018 17:31:08 +0900 Received: by mo-csw.securemx.jp (mx-mo-csw1516) id w2U8V3Cn022781; Fri, 30 Mar 2018 17:31:03 +0900 X-Iguazu-Qid: 34tKUSOYRFihimjNv4 X-Iguazu-QSIG: v=1; s=0; t=1522398663; q=34tKUSOYRFihimjNv4; m=UPyLXV+Km0r9LO7D/GGrR45XyVDc59hQrtdOsaPPHsQ= Received: from imx12.toshiba.co.jp (imx12.toshiba.co.jp [61.202.160.132]) by relay.securemx.jp (mx-mr1512) id w2U8V2G2018077; Fri, 30 Mar 2018 17:31:02 +0900 Received: from hop101.toshiba.co.jp ([133.199.85.107]) by imx12.toshiba.co.jp with ESMTP id w2U8V2xt002574; Fri, 30 Mar 2018 17:31:02 +0900 (JST) Content-Transfer-Encoding: 7bit From: Masanobu Koike To: jmorris@namei.org, serge@hallyn.com, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Masanobu Koike Subject: [RFC v3 2/2] WhiteEgret: Add an example of user application. Date: Fri, 30 Mar 2018 17:30:59 +0900 X-TSB-HOP: ON Message-Id: <20180330083059.2296-1-masanobu2.koike@toshiba.co.jp> X-Mailer: git-send-email 2.14.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A user application is required to use WhiteEgret. This RFC provides a sample user application program. Usage sample-we-user This sample user application always returns "not permit" for the executable specified by the argument , otherwise always returns "permit". Set the absolute path of an executable to be blocked for . Example sample-we-user /bin/df Then every executions of /bin/df are blocked. The other commands can be issued normally. How to build To build this sample user application, set option CONFIG_SAMPLE_WHITEEGRET=y. Remark This sample user application does not use a whitelist. It simply returns "not permit" only when WhiteEgret sends the absolute path of argv[1] to the application. The reason why this sample user application adopts blacklist-like approach is to avoid a host to become uncontrollable. Namely, if this sample provides a sample whitelist and it misses indispensable executable components for a host, the host cannot run or stop normally. Because indispensable executable components depend on each environment, we decide not to provide a whitelisting-type sample user application. Signed-off-by: Masanobu Koike --- samples/Kconfig | 6 ++++ samples/Makefile | 2 +- samples/whiteegret/Makefile | 14 ++++++++ samples/whiteegret/checkwl.c | 57 +++++++++++++++++++++++++++++ samples/whiteegret/checkwl.h | 26 ++++++++++++++ samples/whiteegret/main.c | 86 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 190 insertions(+), 1 deletion(-) create mode 100644 samples/whiteegret/Makefile create mode 100644 samples/whiteegret/checkwl.c create mode 100644 samples/whiteegret/checkwl.h create mode 100644 samples/whiteegret/main.c diff --git a/samples/Kconfig b/samples/Kconfig index c332a3b9de05..be6b03a70f23 100644 --- a/samples/Kconfig +++ b/samples/Kconfig @@ -117,4 +117,10 @@ config SAMPLE_STATX help Build example userspace program to use the new extended-stat syscall. +config SAMPLE_WHITEEGRET + bool "Build WhiteEgret sample user application" + depends on SECURITY_WHITEEGRET + help + Build sample userspace application for WhiteEgret LSM module. + endif # SAMPLES diff --git a/samples/Makefile b/samples/Makefile index db54e766ddb1..00bcba542e46 100644 --- a/samples/Makefile +++ b/samples/Makefile @@ -3,4 +3,4 @@ obj-$(CONFIG_SAMPLES) += kobject/ kprobes/ trace_events/ livepatch/ \ hw_breakpoint/ kfifo/ kdb/ hidraw/ rpmsg/ seccomp/ \ configfs/ connector/ v4l/ trace_printk/ blackfin/ \ - vfio-mdev/ statx/ + vfio-mdev/ statx/ whiteegret/ diff --git a/samples/whiteegret/Makefile b/samples/whiteegret/Makefile new file mode 100644 index 000000000000..77a01643c45d --- /dev/null +++ b/samples/whiteegret/Makefile @@ -0,0 +1,14 @@ +# kbuild trick to avoid linker error. Can be omitted if a module is built. +obj- := dummy.o + +# List of programs to build +hostprogs-$(CONFIG_SAMPLE_WHITEEGRET) := sample-we-user + +sample-we-user-objs := main.o checkwl.o + +HOSTCFLAGS += -Wall +HOSTCFLAGS += -I/usr/local/include +HOSTCFLAGS += -I$(srctree)/security/whiteegret + +# Tell kbuild to always build the programs +always := $(hostprogs-y) diff --git a/samples/whiteegret/checkwl.c b/samples/whiteegret/checkwl.c new file mode 100644 index 000000000000..f19eb1054208 --- /dev/null +++ b/samples/whiteegret/checkwl.c @@ -0,0 +1,57 @@ +/* + * WhiteEgret Linux Security Module + * + * Sample program of user's whitelisting application + * + * Copyright (C) 2017-2018 Toshiba Corporation + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, version 2. + */ + +#include +#include +#include "checkwl.h" + +/* + * The function check_whitelist() returns -EACCES + * only when path to be examined equals to @a not_permit_exe. + */ +char not_permit_exe[NOTPERMITEXENAMELENGTH]; + +/** + * check_whitelist - Examine whether the executable input to this function + * is included in whitelist or not. + * + * @result: Result of the examination. + * 0 if the executble is included in whitelist + * -EACCES otherwise ("not included") + * + * Returns 0 for success, -1 otherwise. + */ +int check_whitelist(int *result, struct we_req_user *user) +{ + char *path; + + if (result == NULL) + return -1; + + *result = 0; + + if (user == NULL) + return -1; + + path = user->path; + + /* + * Referring a whitelist is expected at this location. + * However, this sample uses not whitelist but blacklist + * because of avoiding a host to become uncontrollable. + * (not_permit_exe is a blacklist containing only one item.) + */ + if (strncmp(not_permit_exe, path, NOTPERMITEXENAMELENGTH) == 0) + *result = -EACCES; + + return 0; +} diff --git a/samples/whiteegret/checkwl.h b/samples/whiteegret/checkwl.h new file mode 100644 index 000000000000..732959bbcf16 --- /dev/null +++ b/samples/whiteegret/checkwl.h @@ -0,0 +1,26 @@ +/* + * WhiteEgret Linux Security Module + * + * Sample program of user's whitelisting application + * + * Copyright (C) 2017-2018 Toshiba Corporation + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, version 2. + */ + +#ifndef _CHECKWL_H +#define _CHECKWL_H + +#include +#include "we_fs_common.h" + +/* byte length of absolute path of file not to permit execution */ +#define NOTPERMITEXENAMELENGTH 1024 + +extern char not_permit_exe[NOTPERMITEXENAMELENGTH]; + +int check_whitelist(int *result, struct we_req_user *user); + +#endif diff --git a/samples/whiteegret/main.c b/samples/whiteegret/main.c new file mode 100644 index 000000000000..949d188885de --- /dev/null +++ b/samples/whiteegret/main.c @@ -0,0 +1,86 @@ +/* + * WhiteEgret Linux Security Module + * + * Sample program of user's whitelisting application + * + * Copyright (C) 2017-2018 Toshiba Corporation + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, version 2. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "checkwl.h" + +#include +#include "we_fs_common.h" + +#define MAXWAITFROMKER 10 + +static void sigint_catch(int sig) +{ +} + +static void print_usage(void) +{ + fprintf(stderr, "Usage: sample-we-user [file_name]\n"); + fprintf(stderr, "file_name: absolute path of executable"); + fprintf(stderr, "not to permit execution.\n"); +} + +int main(int argc, char *argv[]) +{ + int fd; + struct we_req_user *user; + struct we_ack ack; + char buf[1024]; + int ret; + + if (argc < 2) { + print_usage(); + return -1; + } + + snprintf(not_permit_exe, NOTPERMITEXENAMELENGTH, "%s", argv[1]); + + signal(SIGINT, sigint_catch); + + if (daemon(0, 0) < 0) { + perror("daemon"); + exit(EXIT_FAILURE); + } + + fd = open(WE_DEV_PATH, O_RDWR, 0); + if (fd < 0) { + perror(WE_DEV_PATH); + exit(EXIT_FAILURE); + } + user = (struct we_req_user *)((void *)buf); + + while (1) { + ret = read(fd, (char *)user, 1024); + if (ret < 0) { + perror("read"); + continue; + } + + ack.pid = user->pid; + check_whitelist(&ack.permit, user); + + ret = write(fd, (char *)&ack, sizeof(ack)); + } + + close(fd); + + return 0; +} -- 2.14.1