You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

189 lines
5.4 KiB

  1. From f408c6c45013c80d62ed4b793ee79d76e4b582e0 Mon Sep 17 00:00:00 2001
  2. From: Namjae Jeon <namjae.jeon@samsung.com>
  3. Date: Wed, 11 Aug 2021 15:21:04 +0900
  4. Subject: [PATCH] ksmbd: remove select FS_POSIX_ACL in Kconfig
  5. ksmbd is forcing to turn on FS_POSIX_ACL in Kconfig to use vfs acl
  6. functions(posix_acl_alloc, get_acl, set_posix_acl). OpenWRT and other
  7. platform doesn't use acl and this config is disable by default in
  8. kernel. This patch use IS_ENABLED() to know acl config is enable and use
  9. acl function if it is enable.
  10. Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
  11. ---
  12. Kconfig | 1 -
  13. smb2pdu.c | 8 +++---
  14. smbacl.c | 80 ++++++++++++++++++++++++++++++++-----------------------
  15. vfs.c | 9 +++++++
  16. 4 files changed, 60 insertions(+), 38 deletions(-)
  17. --- a/Kconfig
  18. +++ b/Kconfig
  19. @@ -19,7 +19,6 @@ config SMB_SERVER
  20. select CRYPTO_GCM
  21. select ASN1
  22. select OID_REGISTRY
  23. - select FS_POSIX_ACL
  24. default n
  25. help
  26. Choose Y here if you want to allow SMB3 compliant clients
  27. --- a/smb2pdu.c
  28. +++ b/smb2pdu.c
  29. @@ -2387,9 +2387,11 @@ static void ksmbd_acls_fattr(struct smb_
  30. fattr->cf_mode = inode->i_mode;
  31. fattr->cf_dacls = NULL;
  32. - fattr->cf_acls = get_acl(inode, ACL_TYPE_ACCESS);
  33. - if (S_ISDIR(inode->i_mode))
  34. - fattr->cf_dacls = get_acl(inode, ACL_TYPE_DEFAULT);
  35. + if (IS_ENABLED(CONFIG_FS_POSIX_ACL)) {
  36. + fattr->cf_acls = get_acl(inode, ACL_TYPE_ACCESS);
  37. + if (S_ISDIR(inode->i_mode))
  38. + fattr->cf_dacls = get_acl(inode, ACL_TYPE_DEFAULT);
  39. + }
  40. }
  41. /**
  42. --- a/smbacl.c
  43. +++ b/smbacl.c
  44. @@ -533,22 +533,29 @@ static void parse_dacl(struct user_names
  45. if (acl_state.users->n || acl_state.groups->n) {
  46. acl_state.mask.allow = 0x07;
  47. - fattr->cf_acls = posix_acl_alloc(acl_state.users->n +
  48. - acl_state.groups->n + 4, GFP_KERNEL);
  49. - if (fattr->cf_acls) {
  50. - cf_pace = fattr->cf_acls->a_entries;
  51. - posix_state_to_acl(&acl_state, cf_pace);
  52. +
  53. + if (IS_ENABLED(CONFIG_FS_POSIX_ACL)) {
  54. + fattr->cf_acls =
  55. + posix_acl_alloc(acl_state.users->n +
  56. + acl_state.groups->n + 4, GFP_KERNEL);
  57. + if (fattr->cf_acls) {
  58. + cf_pace = fattr->cf_acls->a_entries;
  59. + posix_state_to_acl(&acl_state, cf_pace);
  60. + }
  61. }
  62. }
  63. if (default_acl_state.users->n || default_acl_state.groups->n) {
  64. default_acl_state.mask.allow = 0x07;
  65. - fattr->cf_dacls =
  66. - posix_acl_alloc(default_acl_state.users->n +
  67. - default_acl_state.groups->n + 4, GFP_KERNEL);
  68. - if (fattr->cf_dacls) {
  69. - cf_pdace = fattr->cf_dacls->a_entries;
  70. - posix_state_to_acl(&default_acl_state, cf_pdace);
  71. +
  72. + if (IS_ENABLED(CONFIG_FS_POSIX_ACL)) {
  73. + fattr->cf_dacls =
  74. + posix_acl_alloc(default_acl_state.users->n +
  75. + default_acl_state.groups->n + 4, GFP_KERNEL);
  76. + if (fattr->cf_dacls) {
  77. + cf_pdace = fattr->cf_dacls->a_entries;
  78. + posix_state_to_acl(&default_acl_state, cf_pdace);
  79. + }
  80. }
  81. }
  82. free_acl_state(&acl_state);
  83. @@ -1221,31 +1228,36 @@ int smb_check_perm_dacl(struct ksmbd_con
  84. granted = GENERIC_ALL_FLAGS;
  85. }
  86. - posix_acls = get_acl(d_inode(path->dentry), ACL_TYPE_ACCESS);
  87. - if (posix_acls && !found) {
  88. - unsigned int id = -1;
  89. -
  90. - pa_entry = posix_acls->a_entries;
  91. - for (i = 0; i < posix_acls->a_count; i++, pa_entry++) {
  92. - if (pa_entry->e_tag == ACL_USER)
  93. - id = from_kuid(user_ns,
  94. - pa_entry->e_uid);
  95. - else if (pa_entry->e_tag == ACL_GROUP)
  96. - id = from_kgid(user_ns,
  97. - pa_entry->e_gid);
  98. - else
  99. - continue;
  100. -
  101. - if (id == uid) {
  102. - mode_to_access_flags(pa_entry->e_perm, 0777, &access_bits);
  103. - if (!access_bits)
  104. - access_bits = SET_MINIMUM_RIGHTS;
  105. - goto check_access_bits;
  106. + if (IS_ENABLED(CONFIG_FS_POSIX_ACL)) {
  107. + posix_acls = get_acl(d_inode(path->dentry), ACL_TYPE_ACCESS);
  108. + if (posix_acls && !found) {
  109. + unsigned int id = -1;
  110. +
  111. + pa_entry = posix_acls->a_entries;
  112. + for (i = 0; i < posix_acls->a_count; i++, pa_entry++) {
  113. + if (pa_entry->e_tag == ACL_USER)
  114. + id = from_kuid(user_ns,
  115. + pa_entry->e_uid);
  116. + else if (pa_entry->e_tag == ACL_GROUP)
  117. + id = from_kgid(user_ns,
  118. + pa_entry->e_gid);
  119. + else
  120. + continue;
  121. +
  122. + if (id == uid) {
  123. + mode_to_access_flags(pa_entry->e_perm,
  124. + 0777,
  125. + &access_bits);
  126. + if (!access_bits)
  127. + access_bits =
  128. + SET_MINIMUM_RIGHTS;
  129. + goto check_access_bits;
  130. + }
  131. }
  132. }
  133. + if (posix_acls)
  134. + posix_acl_release(posix_acls);
  135. }
  136. - if (posix_acls)
  137. - posix_acl_release(posix_acls);
  138. if (!found) {
  139. if (others_ace) {
  140. @@ -1308,7 +1320,7 @@ int set_info_sec(struct ksmbd_conn *conn
  141. ksmbd_vfs_remove_acl_xattrs(user_ns, path->dentry);
  142. /* Update posix acls */
  143. - if (fattr.cf_dacls) {
  144. + if (IS_ENABLED(CONFIG_FS_POSIX_ACL) && fattr.cf_dacls) {
  145. #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0)
  146. rc = set_posix_acl(user_ns, inode,
  147. ACL_TYPE_ACCESS,
  148. --- a/vfs.c
  149. +++ b/vfs.c
  150. @@ -1508,6 +1508,9 @@ static struct xattr_smb_acl *ksmbd_vfs_m
  151. struct xattr_acl_entry *xa_entry;
  152. int i;
  153. + if (!IS_ENABLED(CONFIG_FS_POSIX_ACL))
  154. + return NULL;
  155. +
  156. posix_acls = get_acl(inode, acl_type);
  157. if (!posix_acls)
  158. return NULL;
  159. @@ -2322,6 +2325,9 @@ int ksmbd_vfs_set_init_posix_acl(struct
  160. struct posix_acl *acls;
  161. int rc;
  162. + if (!IS_ENABLED(CONFIG_FS_POSIX_ACL))
  163. + return -EOPNOTSUPP;
  164. +
  165. ksmbd_debug(SMB, "Set posix acls\n");
  166. rc = init_acl_state(&acl_state, 1);
  167. if (rc)
  168. @@ -2377,6 +2383,9 @@ int ksmbd_vfs_inherit_posix_acl(struct u
  169. struct posix_acl_entry *pace;
  170. int rc, i;
  171. + if (!IS_ENABLED(CONFIG_FS_POSIX_ACL))
  172. + return -EOPNOTSUPP;
  173. +
  174. acls = get_acl(parent_inode, ACL_TYPE_DEFAULT);
  175. if (!acls)
  176. return -ENOENT;