Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757488Ab3FHBKn (ORCPT ); Fri, 7 Jun 2013 21:10:43 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:59715 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757357Ab3FHBKl (ORCPT ); Fri, 7 Jun 2013 21:10:41 -0400 X-AuditID: cbfee68e-b7f276d000002279-ca-51b2848fbf33 Message-id: <1370653763.3600.55.camel@kjgkr> Subject: Re: [PATCH 2/2 v2] f2fs: support xattr security labels From: Jaegeuk Kim Reply-to: jaegeuk.kim@samsung.com To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Date: Sat, 08 Jun 2013 10:09:23 +0900 In-reply-to: <1370592580.3600.42.camel@kjgkr> References: <1370584557-20592-1-git-send-email-jaegeuk.kim@samsung.com> <1370584557-20592-2-git-send-email-jaegeuk.kim@samsung.com> <1370592580.3600.42.camel@kjgkr> Organization: samsung Content-type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-DOxcAI3Dyvx9EvxpZk+g" X-Mailer: Evolution 3.2.3-0ubuntu6 MIME-version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrFIsWRmVeSWpSXmKPExsVy+t8zA93+lk2BBv+WWllcWuRusWfvSRaL y7vmsDkwe+xe8JnJ4/MmuQCmKC6blNSczLLUIn27BK6MC/3vGQt+elb8+fyLpYHxg20XIweH hICJxPN5Cl2MnECmmMSFe+vZuhi5OIQEljFKXDl+jhkiYSJx/8p1JojEdEaJdTu2M4IkhARe M0osn1gDYvMK6EisvvofrEFYwF7ixLJfLCAL2AS0JTbvN4AoV5R4u/8uK0hYBMi+/N4JxGQW 8JDYdawUpIJFQFXiwsljYMM5BXQlTu7cxQyxdQWjxMTDy1lAEvwCohInWz+BFTELVEl8WtnO AnGmksTu9k52iGsEJX5MvscC0iwh8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4uEVMN8UKMSaWFZcmXuIUQVozqMNqy8wSrHk5eelKonwNm7aGCjEm5JYWZVa lB9fVJqTWnyIcSIjMDwmMkuJJucD01ZeSbyhsYmZkaWRmYWRibk5LYWVxHkPtloHCgmkJ5ak ZqemFqQWwRzFxMEp1cBoK936W5NLQrM7tOamyKxfXzWbJbY8tolImnppfhxfraugssHkFU+k TH7fmO6fd7abqUKMi2e7xYKDIZ+2T47zWfXC6ZFl9uPObaetV053e+2xYp/1qS2TL9l6n549 UcXCa2Ls4ljh2dt17l9rqOp602B4dO5EBvFfczN/rCu6rqTu+fzJMg0BJZbijERDLeai4kQA Q2raV38DAAA= DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 9409 Lines: 308 --=-DOxcAI3Dyvx9EvxpZk+g Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Change log from v2: o fix description and simplify a code line (commented by Casey Schaufler) Change log from v1: o fix a bug =46rom 9f889afcd74a58d9a538fa02f4af31d11eb17c54 Mon Sep 17 00:00:00 2001 From: Jaegeuk Kim Date: Mon, 3 Jun 2013 19:46:19 +0900 Subject: [PATCH] f2fs: support xattr security labels Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-f2fs= -devel@lists.sourceforge.net This patch adds the support of security labels for f2fs, which will be used by Linus Security Models (LSMs). Quote from http://en.wikipedia.org/wiki/Linux_Security_Modules: "Linux Security Modules (LSM) is a framework that allows the Linux kernel t= o support a variety of computer security models while avoiding favoritism tow= ard any single security implementation. The framework is licensed under the ter= ms of the GNU General Public License and is standard part of the Linux kernel sin= ce Linux 2.6. AppArmor, SELinux, Smack and TOMOYO Linux are the currently acce= pted modules in the official kernel.". Signed-off-by: Jaegeuk Kim --- fs/f2fs/Kconfig | 12 +++++++++++ fs/f2fs/dir.c | 5 +++++ fs/f2fs/xattr.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++= +--- fs/f2fs/xattr.h | 12 ++++++++++- 4 files changed, 87 insertions(+), 4 deletions(-) diff --git a/fs/f2fs/Kconfig b/fs/f2fs/Kconfig index fd27e7e..e06e099 100644 --- a/fs/f2fs/Kconfig +++ b/fs/f2fs/Kconfig @@ -51,3 +51,15 @@ config F2FS_FS_POSIX_ACL Linux website . =20 If you don't know what Access Control Lists are, say N + +config F2FS_FS_SECURITY + bool "F2FS Security Labels" + depends on F2FS_FS_XATTR + help + Security labels provide an access control facility to support Linux + Security Models (LSMs) accepted by AppArmor, SELinux, Smack and TOMOYO + Linux. This option enables an extended attribute handler for file + security labels in the f2fs filesystem, so that it requires enabling + the extended attribute support in advance. + + If you are not using a security module, say N. diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c index 67e2d13..81a1d6f 100644 --- a/fs/f2fs/dir.c +++ b/fs/f2fs/dir.c @@ -13,6 +13,7 @@ #include "f2fs.h" #include "node.h" #include "acl.h" +#include "xattr.h" =20 static unsigned long dir_blocks(struct inode *inode) { @@ -334,6 +335,10 @@ static struct page *init_inode_metadata(struct inode *= inode, if (err) goto error; =20 + err =3D f2fs_init_security(inode, dir, name); + if (err) + goto error; + wait_on_page_writeback(page); } else { page =3D get_node_page(F2FS_SB(dir->i_sb), inode->i_ino); diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c index ae61f35..c06e8a3 100644 --- a/fs/f2fs/xattr.c +++ b/fs/f2fs/xattr.c @@ -20,6 +20,7 @@ */ #include #include +#include #include "f2fs.h" #include "xattr.h" =20 @@ -43,6 +44,10 @@ static size_t f2fs_xattr_generic_list(struct dentry *den= try, char *list, prefix =3D XATTR_TRUSTED_PREFIX; prefix_len =3D XATTR_TRUSTED_PREFIX_LEN; break; + case F2FS_XATTR_INDEX_SECURITY: + prefix =3D XATTR_SECURITY_PREFIX; + prefix_len =3D XATTR_SECURITY_PREFIX_LEN; + break; default: return -EINVAL; } @@ -50,7 +55,7 @@ static size_t f2fs_xattr_generic_list(struct dentry *dent= ry, char *list, total_len =3D prefix_len + name_len + 1; if (list && total_len <=3D list_size) { memcpy(list, prefix, prefix_len); - memcpy(list+prefix_len, name, name_len); + memcpy(list + prefix_len, name, name_len); list[prefix_len + name_len] =3D '\0'; } return total_len; @@ -70,13 +75,14 @@ static int f2fs_xattr_generic_get(struct dentry *dentry= , const char *name, if (!capable(CAP_SYS_ADMIN)) return -EPERM; break; + case F2FS_XATTR_INDEX_SECURITY: + break; default: return -EINVAL; } if (strcmp(name, "") =3D=3D 0) return -EINVAL; - return f2fs_getxattr(dentry->d_inode, type, name, - buffer, size); + return f2fs_getxattr(dentry->d_inode, type, name, buffer, size); } =20 static int f2fs_xattr_generic_set(struct dentry *dentry, const char *name, @@ -93,6 +99,8 @@ static int f2fs_xattr_generic_set(struct dentry *dentry, = const char *name, if (!capable(CAP_SYS_ADMIN)) return -EPERM; break; + case F2FS_XATTR_INDEX_SECURITY: + break; default: return -EINVAL; } @@ -145,6 +153,40 @@ static int f2fs_xattr_advise_set(struct dentry *dentry= , const char *name, return 0; } =20 +#ifdef CONFIG_F2FS_FS_SECURITY +static int f2fs_initxattrs(struct inode *inode, const struct xattr *xattr_= array, + void *fs_info) +{ + const struct xattr *xattr; + char *name; + int err =3D 0; + + for (xattr =3D xattr_array; xattr->name !=3D NULL; xattr++) { + name =3D kmalloc(XATTR_SECURITY_PREFIX_LEN + + strlen(xattr->name) + 1, GFP_NOFS); + if (!name) { + err =3D -ENOMEM; + break; + } + strcpy(name, XATTR_SECURITY_PREFIX); + sprintf(name, XATTR_SECURITY_PREFIX "%s", xattr->name); + err =3D f2fs_setxattr(inode, F2FS_XATTR_INDEX_SECURITY, name, + xattr->value, xattr->value_len); + kfree(name); + if (err < 0) + break; + } + return err; +} + +int f2fs_init_security(struct inode *inode, struct inode *dir, + const struct qstr *qstr) +{ + return security_inode_init_security(inode, dir, qstr, + &f2fs_initxattrs, NULL); +} +#endif + const struct xattr_handler f2fs_xattr_user_handler =3D { .prefix =3D XATTR_USER_PREFIX, .flags =3D F2FS_XATTR_INDEX_USER, @@ -169,6 +211,14 @@ const struct xattr_handler f2fs_xattr_advise_handler = =3D { .set =3D f2fs_xattr_advise_set, }; =20 +const struct xattr_handler f2fs_xattr_security_handler =3D { + .prefix =3D XATTR_SECURITY_PREFIX, + .flags =3D F2FS_XATTR_INDEX_SECURITY, + .list =3D f2fs_xattr_generic_list, + .get =3D f2fs_xattr_generic_get, + .set =3D f2fs_xattr_generic_set, +}; + static const struct xattr_handler *f2fs_xattr_handler_map[] =3D { [F2FS_XATTR_INDEX_USER] =3D &f2fs_xattr_user_handler, #ifdef CONFIG_F2FS_FS_POSIX_ACL @@ -176,6 +226,9 @@ static const struct xattr_handler *f2fs_xattr_handler_m= ap[] =3D { [F2FS_XATTR_INDEX_POSIX_ACL_DEFAULT] =3D &f2fs_xattr_acl_default_handler, #endif [F2FS_XATTR_INDEX_TRUSTED] =3D &f2fs_xattr_trusted_handler, +#ifdef CONFIG_F2FS_FS_SECURITY + [F2FS_XATTR_INDEX_SECURITY] =3D &f2fs_xattr_security_handler, +#endif [F2FS_XATTR_INDEX_ADVISE] =3D &f2fs_xattr_advise_handler, }; =20 @@ -186,6 +239,9 @@ const struct xattr_handler *f2fs_xattr_handlers[] =3D { &f2fs_xattr_acl_default_handler, #endif &f2fs_xattr_trusted_handler, +#ifdef CONFIG_F2FS_FS_SECURITY + &f2fs_xattr_security_handler, +#endif &f2fs_xattr_advise_handler, NULL, }; diff --git a/fs/f2fs/xattr.h b/fs/f2fs/xattr.h index 49c9558..14e1329 100644 --- a/fs/f2fs/xattr.h +++ b/fs/f2fs/xattr.h @@ -112,6 +112,7 @@ extern const struct xattr_handler f2fs_xattr_trusted_ha= ndler; extern const struct xattr_handler f2fs_xattr_acl_access_handler; extern const struct xattr_handler f2fs_xattr_acl_default_handler; extern const struct xattr_handler f2fs_xattr_advise_handler; +extern const struct xattr_handler f2fs_xattr_security_handler; =20 extern const struct xattr_handler *f2fs_xattr_handlers[]; =20 @@ -121,7 +122,6 @@ extern int f2fs_getxattr(struct inode *inode, int name_= index, const char *name, void *buffer, size_t buffer_size); extern ssize_t f2fs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size); - #else =20 #define f2fs_xattr_handlers NULL @@ -142,4 +142,14 @@ static inline ssize_t f2fs_listxattr(struct dentry *de= ntry, char *buffer, } #endif =20 +#ifdef CONFIG_F2FS_FS_SECURITY +extern int f2fs_init_security(struct inode *inode, struct inode *dir, + const struct qstr *qstr); +#else +static inline int f2fs_init_security(struct inode *inode, struct inode *di= r, + const struct qstr *qstr) +{ + return 0; +} +#endif #endif /* __F2FS_XATTR_H__ */ --=20 1.8.1.3.566.gaa39828 --=20 Jaegeuk Kim Samsung --=-DOxcAI3Dyvx9EvxpZk+g Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQIcBAABAgAGBQJRsoREAAoJEEAUqH6CSFDSAUAP/0sE8UJ5bOiOBGbishloBUKu 7p/qAiqTHpk/PbmSAnHHihAjWiOHj8slEZ5ppiZUdMJs8c7Udb7Ejxr41hOe99VQ vbeuqGs7qozSBiodaTY1jA4buS7fr00T0F//QIVyDghpJk450cmkwHaPm+kgmi4l 2k0PLQ3E1otsjdtW+BswJMocPQ3p9O6zJm2Pr8cIDglln1WA4+JjZUGdrBMKyRL/ SXrZ10TtoHEFrntyhOW9OSHoJi3Joj5p2Bsy16v1Elojf/C8DoQrtypO4RjmpJTN 52K3kwviPlJxjBHKa/uzLlEYDSkRXT2nkL/xBKpfzv1wTFSZKCDIr1xgJyFUN7Q2 qhUfOmkmqQI3Sg3BV5pbAmu7k5KGqkHdenDdVA3uwtoHX6tD3P6M5hTPCHxIZrU2 8gxj9Jazpv/EX8Gm0fdxNV6E87T1CVSCNF7twGAmuR/lRH0+FZW+ZyreCpfp+LqB 6MUf/cNrkEBrVBT/I1EuBpwmeb7VRxsKeZDEdVi6av+jRRALK/V6f68mci8BkGgZ pMNJL0+DhUALezT0mXzd2e87/L7EPSGDVcIwpAYhhKAKujziIfqsr4ZmK4YsqfZO Lj5S2k/7Wb2uFv5AEq1RVNCjdet1Q/hINhka/vgaO+H985w/uLqsVnG4KYyVEJhQ /unz7RIw0ognBgxlDSs0 =8FLk -----END PGP SIGNATURE----- --=-DOxcAI3Dyvx9EvxpZk+g-- -- 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/