Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752433AbbGXKFb (ORCPT ); Fri, 24 Jul 2015 06:05:31 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:32253 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750710AbbGXKF0 (ORCPT ); Fri, 24 Jul 2015 06:05:26 -0400 X-AuditID: cbfec7f4-f79c56d0000012ee-70-55b20de23896 From: Lukasz Pawelczyk To: "Eric W. Biederman" , "Serge E. Hallyn" , Al Viro , Alexey Dobriyan , Andrew Morton , Andy Lutomirski , Arnd Bergmann , Casey Schaufler , David Howells , Eric Dumazet , Eric Paris , Fabian Frederick , Greg KH , James Morris , Jiri Slaby , Joe Perches , John Johansen , Jonathan Corbet , Kees Cook , Lukasz Pawelczyk , Mauro Carvalho Chehab , NeilBrown , Oleg Nesterov , Paul Moore , Stephen Smalley , Tetsuo Handa , Zefan Li , linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov Cc: havner@gmail.com Subject: [PATCH v3 00/11] Smack namespace Date: Fri, 24 Jul 2015 12:04:34 +0200 Message-id: <1437732285-11524-1-git-send-email-l.pawelczyk@samsung.com> X-Mailer: git-send-email 2.4.3 X-Brightmail-Tracker: H4sIAAAAAAAAAzWRe0hTcRzF/W2/e3dnDS7T7KYRtR5QmqlUfJGS/sqLf0nmHxmaSy9Tcmqb mxoG07TM8tEsTKflqyB1zjQltTWZMg2fkQW9FOezhzbFDF3TNOu/c87nwPnjUHxxPXanYuOT OEW8NE5COuPe1e7hw1ZRY6jP4AM/KEoPglJDHQkOrUUAIy0rJEx03EAwl2HHsNaSKYBJi1UA N8f6+ZBjXybhWpWBhLVvXpA3fgZ0o+MYehazSLjbYONB3y059GkreFBxvRrDC+MrDG/aSkmw 3baSoM3OFUCtXkNA7VQKGB9qMDSbshB81BZh0GXOEdDZXsWHwgkzhsGhAQEMOrqJU3vY0e8O zNpXtIgt0eSSrE7zGrOtJZ8FbHmjin3Xfo7N7Jol2FZ9DY/tuW/HrKmsTsBW5RUS7PzkB8w+ y1+v9v8MY/XGGRTsEeZ8IpqLi1VziiMBkc4xlQYjTuz1TJnqHudpkG13DhJSDH2UKX5vJza1 GzM0YiBzkDMlph8hxtxW/c+k85jpgt6/LZL2YX4NGfkbwJVuFjIFDXq0Afi0K/N7bl6QgyjK hT7INHUHbsSY3s/UV7aQG1pEBzILFVm8zbVdzIBhERegLeXIqQZt41RRicqLMrmvt1IqV6ri Zd5RCfJGtPni4nNUZfE3I5pCkq2iDu3TUDEhVStT5WbEUHyJq8jJsh6JoqWpVzhFwgWFKo5T mpEHhSXbRWVtP86KaZk0ibvEcYmc4j/lUUJ3DSKa8p54KTxJt6A71fElCcXZRYOdxy8vcV8e d/aGD0wTVl3LTtveoB3+hcfUAabZl4Ymff/ViOSQ8YUxUiOLSGsLXlpOWwk6AD4KoV/ykqzL 1h5u1OWqRcJW9fmMzE+n8yMdtn2RIalvv4qtDsu94GHTYsnJGROlzFatzrqUSrAyRup7iK9Q Sv8ABj2eBsECAAA= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5707 Lines: 123 Third version of Smack namespace. Changes here are mostly because of Stephen Smalley's review: https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg899383.html https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg898638.html 1. the label map should be in /proc/.../attr/label_map and be handled generically. 2. The proper file system label (unmapped) should be written only once to remove a state where an incorrect label is on the filesystem. Ad 1: Contrary to what Stephen said this unfortunately required LSM modifications. For reading: the map can be long, in principle longer than PAGE_SIZE to which normal getprocattr hook is limited. So I invented a way for getprocattr to be handled by seq operations. I think it is generic and can be reused nicely by other LSMs. Also it doesn't break current LSM code in any way. This created a new patch. For writing: the default setprocattr arguments were not enough for me to securely decide if the write access should be granted. To be in parallel with user namespace I also needed credentials of the process that actually opened the map (in addition to current). So I added a new argument. This is also a new patch. Ad 2: I really tried to make it work without introducing a new LSM hook but changing a little semantics behind the current ones. Finally I just added a simple inode_pre_setxattr hook that can swap the label before it is written to the filesystem. Hopefully this is ok. I couldn't do this in inode_setxattr hook as Stephen suggested as this hook is called before __vfs_setxattr_noperm which is an exported symbol and is used sometimes without setxattr hence the logic had to be inside that one. This is also a new patch. I also added a new patch that "fixes" smackfs/syslog. I've noticed that inside a namespace when I cat the file it shows "*". Even when I remapped the star. After looking at the code it had it implicitly displayed when it's not set. There were few problems with it: 1. In a namespace we can see a label that is not mapped. 2. There was no way to actually reset the value to default (NULL) 3. It was inconsistent from user space point of view: # cat /smack/syslog * After the reboot the syslog hook doesn't limit anything, the smack_syslog_label is NULL, but it displays star. # echo '*' > /smack/syslog # cat /smack/syslog * >From user space POV this is the same, file has star inside, but now for the hook to pass the current needs to be star as well. And there is no way to reset it back to NULL. So I treated syslog file the same way unconfined and onlycap are handled. If it's empty, there is no label set, hook doesn't limit anything (except for the cap). When it's filled current needs to be equal for the hook to pass (as was before). But now it can be reset back to NULL by writing EINVAL value (e.g. -syslog). The syslog hook itself was not modified, only the file handling. Changes from v2: - fix for config ifdefs in user_ns LSM hooks patch (CONFIG_USER_NS should've been used instead of CONFIG_SECURITY in several places) - new patch for "smack_map" -> "attr/label_map" and new related getprocattr_seq lsm hook. With this change the code in further patches for handling smack_map has been moved to this new method - new patch for setprocattr hook new argument, file's opener creds - new patch for inode_pre_setxattr LSM hook - new patch related to handling smackfs/syslog Changes from v1: - "kernel/exit.c: make sure current's nsproxy != NULL while checking caps" patch has been dropped - fixed the title of the user_ns operations patch Lukasz Pawelczyk (11): user_ns: 3 new LSM hooks for user namespace operations lsm: /proc/$PID/attr/label_map file and getprocattr_seq hook lsm: add file opener's cred to a setprocattr arguments lsm: inode_pre_setxattr hook smack: extend capability functions and fix 2 checks smack: don't use implicit star to display smackfs/syslog smack: abstraction layer for 2 common Smack operations smack: misc cleanups in preparation for a namespace patch smack: namespace groundwork smack: namespace implementation smack: documentation for the Smack namespace Documentation/security/00-INDEX | 2 + Documentation/security/Smack-namespace.txt | 231 +++++++++++ MAINTAINERS | 1 + fs/proc/base.c | 83 +++- fs/xattr.c | 10 + include/linux/lsm_hooks.h | 70 +++- include/linux/security.h | 49 ++- include/linux/user_namespace.h | 4 + kernel/user.c | 3 + kernel/user_namespace.c | 18 + security/apparmor/lsm.c | 5 +- security/security.c | 54 ++- security/selinux/hooks.c | 2 +- security/smack/Kconfig | 12 + security/smack/Makefile | 1 + security/smack/smack.h | 125 +++++- security/smack/smack_access.c | 262 ++++++++++-- security/smack/smack_lsm.c | 615 +++++++++++++++++++++-------- security/smack/smack_ns.c | 443 +++++++++++++++++++++ security/smack/smackfs.c | 188 +++++---- 20 files changed, 1892 insertions(+), 286 deletions(-) create mode 100644 Documentation/security/Smack-namespace.txt create mode 100644 security/smack/smack_ns.c -- 2.4.3 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/