Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | * fs/cifs/cifsacl.c |
| 3 | * |
Steve French | 8b1327f | 2008-03-14 22:37:16 +0000 | [diff] [blame] | 4 | * Copyright (C) International Business Machines Corp., 2007,2008 |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 5 | * Author(s): Steve French (sfrench@us.ibm.com) |
| 6 | * |
| 7 | * Contains the routines for mapping CIFS/NTFS ACLs |
| 8 | * |
| 9 | * This library is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU Lesser General Public License as published |
| 11 | * by the Free Software Foundation; either version 2.1 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This library is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 17 | * the GNU Lesser General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU Lesser General Public License |
| 20 | * along with this library; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | */ |
| 23 | |
Steve French | 6587400 | 2007-09-25 19:53:44 +0000 | [diff] [blame] | 24 | #include <linux/fs.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 25 | #include <linux/slab.h> |
Shirish Pargaonkar | 4d79dba | 2011-04-27 23:34:35 -0500 | [diff] [blame] | 26 | #include <linux/string.h> |
| 27 | #include <linux/keyctl.h> |
| 28 | #include <linux/key-type.h> |
| 29 | #include <keys/user-type.h> |
Steve French | 6587400 | 2007-09-25 19:53:44 +0000 | [diff] [blame] | 30 | #include "cifspdu.h" |
| 31 | #include "cifsglob.h" |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 32 | #include "cifsacl.h" |
Steve French | 6587400 | 2007-09-25 19:53:44 +0000 | [diff] [blame] | 33 | #include "cifsproto.h" |
| 34 | #include "cifs_debug.h" |
Ronnie Sahlberg | 8401e93 | 2020-12-12 13:40:50 -0600 | [diff] [blame] | 35 | #include "fs_context.h" |
Steve French | 6587400 | 2007-09-25 19:53:44 +0000 | [diff] [blame] | 36 | |
Shirish Pargaonkar | 2fbc2f1 | 2010-12-06 14:56:46 -0600 | [diff] [blame] | 37 | /* security id for everyone/world system group */ |
Shirish Pargaonkar | e01b640 | 2007-10-30 04:45:14 +0000 | [diff] [blame] | 38 | static const struct cifs_sid sid_everyone = { |
| 39 | 1, 1, {0, 0, 0, 0, 0, 1}, {0} }; |
Shirish Pargaonkar | 2fbc2f1 | 2010-12-06 14:56:46 -0600 | [diff] [blame] | 40 | /* security id for Authenticated Users system group */ |
| 41 | static const struct cifs_sid sid_authusers = { |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 42 | 1, 1, {0, 0, 0, 0, 0, 5}, {cpu_to_le32(11)} }; |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 43 | |
Steve French | 3514de3 | 2016-10-13 19:06:23 -0500 | [diff] [blame] | 44 | /* S-1-22-1 Unmapped Unix users */ |
| 45 | static const struct cifs_sid sid_unix_users = {1, 1, {0, 0, 0, 0, 0, 22}, |
| 46 | {cpu_to_le32(1), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }; |
| 47 | |
| 48 | /* S-1-22-2 Unmapped Unix groups */ |
| 49 | static const struct cifs_sid sid_unix_groups = { 1, 1, {0, 0, 0, 0, 0, 22}, |
| 50 | {cpu_to_le32(2), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }; |
| 51 | |
| 52 | /* |
Alexander A. Klimov | cba22b1 | 2020-06-27 12:31:25 +0200 | [diff] [blame] | 53 | * See https://technet.microsoft.com/en-us/library/hh509017(v=ws.10).aspx |
Steve French | 3514de3 | 2016-10-13 19:06:23 -0500 | [diff] [blame] | 54 | */ |
| 55 | |
| 56 | /* S-1-5-88 MS NFS and Apple style UID/GID/mode */ |
| 57 | |
| 58 | /* S-1-5-88-1 Unix uid */ |
| 59 | static const struct cifs_sid sid_unix_NFS_users = { 1, 2, {0, 0, 0, 0, 0, 5}, |
| 60 | {cpu_to_le32(88), |
| 61 | cpu_to_le32(1), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }; |
| 62 | |
| 63 | /* S-1-5-88-2 Unix gid */ |
| 64 | static const struct cifs_sid sid_unix_NFS_groups = { 1, 2, {0, 0, 0, 0, 0, 5}, |
| 65 | {cpu_to_le32(88), |
| 66 | cpu_to_le32(2), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }; |
| 67 | |
| 68 | /* S-1-5-88-3 Unix mode */ |
| 69 | static const struct cifs_sid sid_unix_NFS_mode = { 1, 2, {0, 0, 0, 0, 0, 5}, |
| 70 | {cpu_to_le32(88), |
| 71 | cpu_to_le32(3), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }; |
| 72 | |
Jeff Layton | b1a6dc2 | 2012-11-25 08:00:38 -0500 | [diff] [blame] | 73 | static const struct cred *root_cred; |
Shirish Pargaonkar | 9409ae5 | 2011-04-22 12:09:36 -0500 | [diff] [blame] | 74 | |
Shirish Pargaonkar | 4d79dba | 2011-04-27 23:34:35 -0500 | [diff] [blame] | 75 | static int |
David Howells | cf7f601 | 2012-09-13 13:06:29 +0100 | [diff] [blame] | 76 | cifs_idmap_key_instantiate(struct key *key, struct key_preparsed_payload *prep) |
Shirish Pargaonkar | 4d79dba | 2011-04-27 23:34:35 -0500 | [diff] [blame] | 77 | { |
| 78 | char *payload; |
| 79 | |
Jeff Layton | 41a9f1f | 2012-12-03 06:05:29 -0500 | [diff] [blame] | 80 | /* |
| 81 | * If the payload is less than or equal to the size of a pointer, then |
| 82 | * an allocation here is wasteful. Just copy the data directly to the |
| 83 | * payload.value union member instead. |
| 84 | * |
| 85 | * With this however, you must check the datalen before trying to |
| 86 | * dereference payload.data! |
| 87 | */ |
Jeff Layton | 1f63068 | 2012-12-03 06:05:31 -0500 | [diff] [blame] | 88 | if (prep->datalen <= sizeof(key->payload)) { |
David Howells | 146aa8b | 2015-10-21 14:04:48 +0100 | [diff] [blame] | 89 | key->payload.data[0] = NULL; |
| 90 | memcpy(&key->payload, prep->data, prep->datalen); |
| 91 | } else { |
| 92 | payload = kmemdup(prep->data, prep->datalen, GFP_KERNEL); |
| 93 | if (!payload) |
| 94 | return -ENOMEM; |
| 95 | key->payload.data[0] = payload; |
Jeff Layton | 41a9f1f | 2012-12-03 06:05:29 -0500 | [diff] [blame] | 96 | } |
Shirish Pargaonkar | 4d79dba | 2011-04-27 23:34:35 -0500 | [diff] [blame] | 97 | |
David Howells | cf7f601 | 2012-09-13 13:06:29 +0100 | [diff] [blame] | 98 | key->datalen = prep->datalen; |
Shirish Pargaonkar | 4d79dba | 2011-04-27 23:34:35 -0500 | [diff] [blame] | 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | static inline void |
| 103 | cifs_idmap_key_destroy(struct key *key) |
| 104 | { |
Jeff Layton | 1f63068 | 2012-12-03 06:05:31 -0500 | [diff] [blame] | 105 | if (key->datalen > sizeof(key->payload)) |
David Howells | 146aa8b | 2015-10-21 14:04:48 +0100 | [diff] [blame] | 106 | kfree(key->payload.data[0]); |
Shirish Pargaonkar | 4d79dba | 2011-04-27 23:34:35 -0500 | [diff] [blame] | 107 | } |
| 108 | |
Jeff Layton | b1a6dc2 | 2012-11-25 08:00:38 -0500 | [diff] [blame] | 109 | static struct key_type cifs_idmap_key_type = { |
Shirish Pargaonkar | c4aca0c | 2011-05-06 02:35:00 -0500 | [diff] [blame] | 110 | .name = "cifs.idmap", |
Shirish Pargaonkar | 4d79dba | 2011-04-27 23:34:35 -0500 | [diff] [blame] | 111 | .instantiate = cifs_idmap_key_instantiate, |
| 112 | .destroy = cifs_idmap_key_destroy, |
| 113 | .describe = user_describe, |
Shirish Pargaonkar | 4d79dba | 2011-04-27 23:34:35 -0500 | [diff] [blame] | 114 | }; |
| 115 | |
Jeff Layton | faa65f0 | 2012-12-03 06:05:29 -0500 | [diff] [blame] | 116 | static char * |
| 117 | sid_to_key_str(struct cifs_sid *sidptr, unsigned int type) |
Shirish Pargaonkar | 9409ae5 | 2011-04-22 12:09:36 -0500 | [diff] [blame] | 118 | { |
Jeff Layton | faa65f0 | 2012-12-03 06:05:29 -0500 | [diff] [blame] | 119 | int i, len; |
Jeff Layton | ee13b2b | 2012-11-25 08:00:38 -0500 | [diff] [blame] | 120 | unsigned int saval; |
Jeff Layton | faa65f0 | 2012-12-03 06:05:29 -0500 | [diff] [blame] | 121 | char *sidstr, *strptr; |
Jeff Layton | 193cdd8 | 2012-12-10 06:10:44 -0500 | [diff] [blame] | 122 | unsigned long long id_auth_val; |
Jeff Layton | faa65f0 | 2012-12-03 06:05:29 -0500 | [diff] [blame] | 123 | |
| 124 | /* 3 bytes for prefix */ |
| 125 | sidstr = kmalloc(3 + SID_STRING_BASE_SIZE + |
| 126 | (SID_STRING_SUBAUTH_SIZE * sidptr->num_subauth), |
| 127 | GFP_KERNEL); |
| 128 | if (!sidstr) |
| 129 | return sidstr; |
Shirish Pargaonkar | 9409ae5 | 2011-04-22 12:09:36 -0500 | [diff] [blame] | 130 | |
| 131 | strptr = sidstr; |
Jeff Layton | faa65f0 | 2012-12-03 06:05:29 -0500 | [diff] [blame] | 132 | len = sprintf(strptr, "%cs:S-%hhu", type == SIDOWNER ? 'o' : 'g', |
| 133 | sidptr->revision); |
| 134 | strptr += len; |
Shirish Pargaonkar | 9409ae5 | 2011-04-22 12:09:36 -0500 | [diff] [blame] | 135 | |
Jeff Layton | 193cdd8 | 2012-12-10 06:10:44 -0500 | [diff] [blame] | 136 | /* The authority field is a single 48-bit number */ |
| 137 | id_auth_val = (unsigned long long)sidptr->authority[5]; |
| 138 | id_auth_val |= (unsigned long long)sidptr->authority[4] << 8; |
| 139 | id_auth_val |= (unsigned long long)sidptr->authority[3] << 16; |
| 140 | id_auth_val |= (unsigned long long)sidptr->authority[2] << 24; |
| 141 | id_auth_val |= (unsigned long long)sidptr->authority[1] << 32; |
| 142 | id_auth_val |= (unsigned long long)sidptr->authority[0] << 48; |
| 143 | |
| 144 | /* |
| 145 | * MS-DTYP states that if the authority is >= 2^32, then it should be |
| 146 | * expressed as a hex value. |
| 147 | */ |
| 148 | if (id_auth_val <= UINT_MAX) |
| 149 | len = sprintf(strptr, "-%llu", id_auth_val); |
| 150 | else |
| 151 | len = sprintf(strptr, "-0x%llx", id_auth_val); |
| 152 | |
| 153 | strptr += len; |
Shirish Pargaonkar | 9409ae5 | 2011-04-22 12:09:36 -0500 | [diff] [blame] | 154 | |
| 155 | for (i = 0; i < sidptr->num_subauth; ++i) { |
| 156 | saval = le32_to_cpu(sidptr->sub_auth[i]); |
Jeff Layton | faa65f0 | 2012-12-03 06:05:29 -0500 | [diff] [blame] | 157 | len = sprintf(strptr, "-%u", saval); |
| 158 | strptr += len; |
Shirish Pargaonkar | 9409ae5 | 2011-04-22 12:09:36 -0500 | [diff] [blame] | 159 | } |
Jeff Layton | faa65f0 | 2012-12-03 06:05:29 -0500 | [diff] [blame] | 160 | |
| 161 | return sidstr; |
Shirish Pargaonkar | 9409ae5 | 2011-04-22 12:09:36 -0500 | [diff] [blame] | 162 | } |
| 163 | |
Jeff Layton | 436bb43 | 2012-11-25 08:00:36 -0500 | [diff] [blame] | 164 | /* |
| 165 | * if the two SIDs (roughly equivalent to a UUID for a user or group) are |
| 166 | * the same returns zero, if they do not match returns non-zero. |
| 167 | */ |
| 168 | static int |
| 169 | compare_sids(const struct cifs_sid *ctsid, const struct cifs_sid *cwsid) |
| 170 | { |
| 171 | int i; |
| 172 | int num_subauth, num_sat, num_saw; |
| 173 | |
| 174 | if ((!ctsid) || (!cwsid)) |
| 175 | return 1; |
| 176 | |
| 177 | /* compare the revision */ |
| 178 | if (ctsid->revision != cwsid->revision) { |
| 179 | if (ctsid->revision > cwsid->revision) |
| 180 | return 1; |
| 181 | else |
| 182 | return -1; |
| 183 | } |
| 184 | |
| 185 | /* compare all of the six auth values */ |
| 186 | for (i = 0; i < NUM_AUTHS; ++i) { |
| 187 | if (ctsid->authority[i] != cwsid->authority[i]) { |
| 188 | if (ctsid->authority[i] > cwsid->authority[i]) |
| 189 | return 1; |
| 190 | else |
| 191 | return -1; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | /* compare all of the subauth values if any */ |
| 196 | num_sat = ctsid->num_subauth; |
| 197 | num_saw = cwsid->num_subauth; |
| 198 | num_subauth = num_sat < num_saw ? num_sat : num_saw; |
| 199 | if (num_subauth) { |
| 200 | for (i = 0; i < num_subauth; ++i) { |
| 201 | if (ctsid->sub_auth[i] != cwsid->sub_auth[i]) { |
| 202 | if (le32_to_cpu(ctsid->sub_auth[i]) > |
| 203 | le32_to_cpu(cwsid->sub_auth[i])) |
| 204 | return 1; |
| 205 | else |
| 206 | return -1; |
| 207 | } |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | return 0; /* sids compare/match */ |
| 212 | } |
| 213 | |
Steve French | 3514de3 | 2016-10-13 19:06:23 -0500 | [diff] [blame] | 214 | static bool |
| 215 | is_well_known_sid(const struct cifs_sid *psid, uint32_t *puid, bool is_group) |
| 216 | { |
| 217 | int i; |
| 218 | int num_subauth; |
| 219 | const struct cifs_sid *pwell_known_sid; |
| 220 | |
| 221 | if (!psid || (puid == NULL)) |
| 222 | return false; |
| 223 | |
| 224 | num_subauth = psid->num_subauth; |
| 225 | |
| 226 | /* check if Mac (or Windows NFS) vs. Samba format for Unix owner SID */ |
| 227 | if (num_subauth == 2) { |
| 228 | if (is_group) |
| 229 | pwell_known_sid = &sid_unix_groups; |
| 230 | else |
| 231 | pwell_known_sid = &sid_unix_users; |
| 232 | } else if (num_subauth == 3) { |
| 233 | if (is_group) |
| 234 | pwell_known_sid = &sid_unix_NFS_groups; |
| 235 | else |
| 236 | pwell_known_sid = &sid_unix_NFS_users; |
| 237 | } else |
| 238 | return false; |
| 239 | |
| 240 | /* compare the revision */ |
| 241 | if (psid->revision != pwell_known_sid->revision) |
| 242 | return false; |
| 243 | |
| 244 | /* compare all of the six auth values */ |
| 245 | for (i = 0; i < NUM_AUTHS; ++i) { |
| 246 | if (psid->authority[i] != pwell_known_sid->authority[i]) { |
| 247 | cifs_dbg(FYI, "auth %d did not match\n", i); |
| 248 | return false; |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | if (num_subauth == 2) { |
| 253 | if (psid->sub_auth[0] != pwell_known_sid->sub_auth[0]) |
| 254 | return false; |
| 255 | |
| 256 | *puid = le32_to_cpu(psid->sub_auth[1]); |
| 257 | } else /* 3 subauths, ie Windows/Mac style */ { |
| 258 | *puid = le32_to_cpu(psid->sub_auth[0]); |
| 259 | if ((psid->sub_auth[0] != pwell_known_sid->sub_auth[0]) || |
| 260 | (psid->sub_auth[1] != pwell_known_sid->sub_auth[1])) |
| 261 | return false; |
| 262 | |
| 263 | *puid = le32_to_cpu(psid->sub_auth[2]); |
| 264 | } |
| 265 | |
| 266 | cifs_dbg(FYI, "Unix UID %d returned from SID\n", *puid); |
| 267 | return true; /* well known sid found, uid returned */ |
| 268 | } |
| 269 | |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 270 | static __u16 |
Jeff Layton | 36960e4 | 2012-11-03 09:37:28 -0400 | [diff] [blame] | 271 | cifs_copy_sid(struct cifs_sid *dst, const struct cifs_sid *src) |
| 272 | { |
Jeff Layton | 36f87ee | 2012-11-25 08:00:37 -0500 | [diff] [blame] | 273 | int i; |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 274 | __u16 size = 1 + 1 + 6; |
Jeff Layton | 36f87ee | 2012-11-25 08:00:37 -0500 | [diff] [blame] | 275 | |
| 276 | dst->revision = src->revision; |
Jeff Layton | 30c9d6c | 2012-11-25 08:00:37 -0500 | [diff] [blame] | 277 | dst->num_subauth = min_t(u8, src->num_subauth, SID_MAX_SUB_AUTHORITIES); |
Jeff Layton | 36f87ee | 2012-11-25 08:00:37 -0500 | [diff] [blame] | 278 | for (i = 0; i < NUM_AUTHS; ++i) |
| 279 | dst->authority[i] = src->authority[i]; |
| 280 | for (i = 0; i < dst->num_subauth; ++i) |
| 281 | dst->sub_auth[i] = src->sub_auth[i]; |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 282 | size += (dst->num_subauth * 4); |
| 283 | |
| 284 | return size; |
Jeff Layton | 36960e4 | 2012-11-03 09:37:28 -0400 | [diff] [blame] | 285 | } |
| 286 | |
Jeff Layton | faa65f0 | 2012-12-03 06:05:29 -0500 | [diff] [blame] | 287 | static int |
| 288 | id_to_sid(unsigned int cid, uint sidtype, struct cifs_sid *ssid) |
Shirish Pargaonkar | 9409ae5 | 2011-04-22 12:09:36 -0500 | [diff] [blame] | 289 | { |
| 290 | int rc; |
Shirish Pargaonkar | 21fed0d | 2011-08-09 14:30:48 -0500 | [diff] [blame] | 291 | struct key *sidkey; |
Jeff Layton | 2ae0302 | 2012-12-03 06:05:30 -0500 | [diff] [blame] | 292 | struct cifs_sid *ksid; |
| 293 | unsigned int ksid_size; |
Jeff Layton | faa65f0 | 2012-12-03 06:05:29 -0500 | [diff] [blame] | 294 | char desc[3 + 10 + 1]; /* 3 byte prefix + 10 bytes for value + NULL */ |
Shirish Pargaonkar | 21fed0d | 2011-08-09 14:30:48 -0500 | [diff] [blame] | 295 | const struct cred *saved_cred; |
Shirish Pargaonkar | 21fed0d | 2011-08-09 14:30:48 -0500 | [diff] [blame] | 296 | |
Jeff Layton | faa65f0 | 2012-12-03 06:05:29 -0500 | [diff] [blame] | 297 | rc = snprintf(desc, sizeof(desc), "%ci:%u", |
| 298 | sidtype == SIDOWNER ? 'o' : 'g', cid); |
| 299 | if (rc >= sizeof(desc)) |
Shirish Pargaonkar | 21fed0d | 2011-08-09 14:30:48 -0500 | [diff] [blame] | 300 | return -EINVAL; |
| 301 | |
Jeff Layton | faa65f0 | 2012-12-03 06:05:29 -0500 | [diff] [blame] | 302 | rc = 0; |
| 303 | saved_cred = override_creds(root_cred); |
Linus Torvalds | 028db3e | 2019-07-10 18:43:43 -0700 | [diff] [blame] | 304 | sidkey = request_key(&cifs_idmap_key_type, desc, ""); |
Jeff Layton | faa65f0 | 2012-12-03 06:05:29 -0500 | [diff] [blame] | 305 | if (IS_ERR(sidkey)) { |
Shirish Pargaonkar | 21fed0d | 2011-08-09 14:30:48 -0500 | [diff] [blame] | 306 | rc = -EINVAL; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 307 | cifs_dbg(FYI, "%s: Can't map %cid %u to a SID\n", |
| 308 | __func__, sidtype == SIDOWNER ? 'u' : 'g', cid); |
Jeff Layton | faa65f0 | 2012-12-03 06:05:29 -0500 | [diff] [blame] | 309 | goto out_revert_creds; |
| 310 | } else if (sidkey->datalen < CIFS_SID_BASE_SIZE) { |
| 311 | rc = -EIO; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 312 | cifs_dbg(FYI, "%s: Downcall contained malformed key (datalen=%hu)\n", |
| 313 | __func__, sidkey->datalen); |
Jeff Layton | 2ae0302 | 2012-12-03 06:05:30 -0500 | [diff] [blame] | 314 | goto invalidate_key; |
Shirish Pargaonkar | 21fed0d | 2011-08-09 14:30:48 -0500 | [diff] [blame] | 315 | } |
Jeff Layton | 2ae0302 | 2012-12-03 06:05:30 -0500 | [diff] [blame] | 316 | |
Jeff Layton | 1f63068 | 2012-12-03 06:05:31 -0500 | [diff] [blame] | 317 | /* |
| 318 | * A sid is usually too large to be embedded in payload.value, but if |
| 319 | * there are no subauthorities and the host has 8-byte pointers, then |
| 320 | * it could be. |
| 321 | */ |
| 322 | ksid = sidkey->datalen <= sizeof(sidkey->payload) ? |
David Howells | 146aa8b | 2015-10-21 14:04:48 +0100 | [diff] [blame] | 323 | (struct cifs_sid *)&sidkey->payload : |
| 324 | (struct cifs_sid *)sidkey->payload.data[0]; |
Jeff Layton | 1f63068 | 2012-12-03 06:05:31 -0500 | [diff] [blame] | 325 | |
Jeff Layton | 2ae0302 | 2012-12-03 06:05:30 -0500 | [diff] [blame] | 326 | ksid_size = CIFS_SID_BASE_SIZE + (ksid->num_subauth * sizeof(__le32)); |
| 327 | if (ksid_size > sidkey->datalen) { |
| 328 | rc = -EIO; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 329 | cifs_dbg(FYI, "%s: Downcall contained malformed key (datalen=%hu, ksid_size=%u)\n", |
| 330 | __func__, sidkey->datalen, ksid_size); |
Jeff Layton | 2ae0302 | 2012-12-03 06:05:30 -0500 | [diff] [blame] | 331 | goto invalidate_key; |
| 332 | } |
Jeff Layton | 1f63068 | 2012-12-03 06:05:31 -0500 | [diff] [blame] | 333 | |
Jeff Layton | 2ae0302 | 2012-12-03 06:05:30 -0500 | [diff] [blame] | 334 | cifs_copy_sid(ssid, ksid); |
Jeff Layton | faa65f0 | 2012-12-03 06:05:29 -0500 | [diff] [blame] | 335 | out_key_put: |
| 336 | key_put(sidkey); |
| 337 | out_revert_creds: |
| 338 | revert_creds(saved_cred); |
Shirish Pargaonkar | 21fed0d | 2011-08-09 14:30:48 -0500 | [diff] [blame] | 339 | return rc; |
Jeff Layton | 2ae0302 | 2012-12-03 06:05:30 -0500 | [diff] [blame] | 340 | |
| 341 | invalidate_key: |
| 342 | key_invalidate(sidkey); |
| 343 | goto out_key_put; |
Shirish Pargaonkar | 21fed0d | 2011-08-09 14:30:48 -0500 | [diff] [blame] | 344 | } |
| 345 | |
Steve French | 9934430 | 2020-10-20 02:02:02 -0500 | [diff] [blame] | 346 | int |
Shirish Pargaonkar | 9409ae5 | 2011-04-22 12:09:36 -0500 | [diff] [blame] | 347 | sid_to_id(struct cifs_sb_info *cifs_sb, struct cifs_sid *psid, |
| 348 | struct cifs_fattr *fattr, uint sidtype) |
| 349 | { |
Qiujun Huang | f2d6793 | 2020-03-04 15:42:51 +0800 | [diff] [blame] | 350 | int rc = 0; |
Jeff Layton | faa65f0 | 2012-12-03 06:05:29 -0500 | [diff] [blame] | 351 | struct key *sidkey; |
| 352 | char *sidstr; |
Shirish Pargaonkar | 9409ae5 | 2011-04-22 12:09:36 -0500 | [diff] [blame] | 353 | const struct cred *saved_cred; |
Ronnie Sahlberg | 8401e93 | 2020-12-12 13:40:50 -0600 | [diff] [blame] | 354 | kuid_t fuid = cifs_sb->ctx->linux_uid; |
| 355 | kgid_t fgid = cifs_sb->ctx->linux_gid; |
Shirish Pargaonkar | 9409ae5 | 2011-04-22 12:09:36 -0500 | [diff] [blame] | 356 | |
Jeff Layton | faa65f0 | 2012-12-03 06:05:29 -0500 | [diff] [blame] | 357 | /* |
| 358 | * If we have too many subauthorities, then something is really wrong. |
| 359 | * Just return an error. |
| 360 | */ |
| 361 | if (unlikely(psid->num_subauth > SID_MAX_SUB_AUTHORITIES)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 362 | cifs_dbg(FYI, "%s: %u subauthorities is too many!\n", |
| 363 | __func__, psid->num_subauth); |
Jeff Layton | faa65f0 | 2012-12-03 06:05:29 -0500 | [diff] [blame] | 364 | return -EIO; |
| 365 | } |
Shirish Pargaonkar | 9409ae5 | 2011-04-22 12:09:36 -0500 | [diff] [blame] | 366 | |
Steve French | 9934430 | 2020-10-20 02:02:02 -0500 | [diff] [blame] | 367 | if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UID_FROM_ACL) || |
| 368 | (cifs_sb_master_tcon(cifs_sb)->posix_extensions)) { |
Steve French | 3514de3 | 2016-10-13 19:06:23 -0500 | [diff] [blame] | 369 | uint32_t unix_id; |
| 370 | bool is_group; |
| 371 | |
| 372 | if (sidtype != SIDOWNER) |
| 373 | is_group = true; |
| 374 | else |
| 375 | is_group = false; |
| 376 | |
| 377 | if (is_well_known_sid(psid, &unix_id, is_group) == false) |
| 378 | goto try_upcall_to_get_id; |
| 379 | |
| 380 | if (is_group) { |
| 381 | kgid_t gid; |
| 382 | gid_t id; |
| 383 | |
| 384 | id = (gid_t)unix_id; |
| 385 | gid = make_kgid(&init_user_ns, id); |
| 386 | if (gid_valid(gid)) { |
| 387 | fgid = gid; |
| 388 | goto got_valid_id; |
| 389 | } |
| 390 | } else { |
| 391 | kuid_t uid; |
| 392 | uid_t id; |
| 393 | |
| 394 | id = (uid_t)unix_id; |
| 395 | uid = make_kuid(&init_user_ns, id); |
| 396 | if (uid_valid(uid)) { |
| 397 | fuid = uid; |
| 398 | goto got_valid_id; |
| 399 | } |
| 400 | } |
| 401 | /* If unable to find uid/gid easily from SID try via upcall */ |
| 402 | } |
| 403 | |
| 404 | try_upcall_to_get_id: |
Jeff Layton | faa65f0 | 2012-12-03 06:05:29 -0500 | [diff] [blame] | 405 | sidstr = sid_to_key_str(psid, sidtype); |
| 406 | if (!sidstr) |
| 407 | return -ENOMEM; |
Shirish Pargaonkar | 9409ae5 | 2011-04-22 12:09:36 -0500 | [diff] [blame] | 408 | |
Jeff Layton | faa65f0 | 2012-12-03 06:05:29 -0500 | [diff] [blame] | 409 | saved_cred = override_creds(root_cred); |
Linus Torvalds | 028db3e | 2019-07-10 18:43:43 -0700 | [diff] [blame] | 410 | sidkey = request_key(&cifs_idmap_key_type, sidstr, ""); |
Jeff Layton | faa65f0 | 2012-12-03 06:05:29 -0500 | [diff] [blame] | 411 | if (IS_ERR(sidkey)) { |
| 412 | rc = -EINVAL; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 413 | cifs_dbg(FYI, "%s: Can't map SID %s to a %cid\n", |
| 414 | __func__, sidstr, sidtype == SIDOWNER ? 'u' : 'g'); |
Jeff Layton | faa65f0 | 2012-12-03 06:05:29 -0500 | [diff] [blame] | 415 | goto out_revert_creds; |
Shirish Pargaonkar | 9409ae5 | 2011-04-22 12:09:36 -0500 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | /* |
Jeff Layton | faa65f0 | 2012-12-03 06:05:29 -0500 | [diff] [blame] | 419 | * FIXME: Here we assume that uid_t and gid_t are same size. It's |
| 420 | * probably a safe assumption but might be better to check based on |
| 421 | * sidtype. |
Shirish Pargaonkar | 9409ae5 | 2011-04-22 12:09:36 -0500 | [diff] [blame] | 422 | */ |
Eric W. Biederman | 355958f | 2013-02-06 00:10:23 -0800 | [diff] [blame] | 423 | BUILD_BUG_ON(sizeof(uid_t) != sizeof(gid_t)); |
Jeff Layton | 41a9f1f | 2012-12-03 06:05:29 -0500 | [diff] [blame] | 424 | if (sidkey->datalen != sizeof(uid_t)) { |
Jeff Layton | faa65f0 | 2012-12-03 06:05:29 -0500 | [diff] [blame] | 425 | rc = -EIO; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 426 | cifs_dbg(FYI, "%s: Downcall contained malformed key (datalen=%hu)\n", |
| 427 | __func__, sidkey->datalen); |
Jeff Layton | 2ae0302 | 2012-12-03 06:05:30 -0500 | [diff] [blame] | 428 | key_invalidate(sidkey); |
Jeff Layton | faa65f0 | 2012-12-03 06:05:29 -0500 | [diff] [blame] | 429 | goto out_key_put; |
Shirish Pargaonkar | 9409ae5 | 2011-04-22 12:09:36 -0500 | [diff] [blame] | 430 | } |
| 431 | |
Eric W. Biederman | 8abf277 | 2013-02-06 00:33:17 -0800 | [diff] [blame] | 432 | if (sidtype == SIDOWNER) { |
| 433 | kuid_t uid; |
| 434 | uid_t id; |
David Howells | 146aa8b | 2015-10-21 14:04:48 +0100 | [diff] [blame] | 435 | memcpy(&id, &sidkey->payload.data[0], sizeof(uid_t)); |
Eric W. Biederman | 8abf277 | 2013-02-06 00:33:17 -0800 | [diff] [blame] | 436 | uid = make_kuid(&init_user_ns, id); |
| 437 | if (uid_valid(uid)) |
| 438 | fuid = uid; |
| 439 | } else { |
| 440 | kgid_t gid; |
| 441 | gid_t id; |
David Howells | 146aa8b | 2015-10-21 14:04:48 +0100 | [diff] [blame] | 442 | memcpy(&id, &sidkey->payload.data[0], sizeof(gid_t)); |
Eric W. Biederman | 8abf277 | 2013-02-06 00:33:17 -0800 | [diff] [blame] | 443 | gid = make_kgid(&init_user_ns, id); |
| 444 | if (gid_valid(gid)) |
| 445 | fgid = gid; |
| 446 | } |
Shirish Pargaonkar | 9409ae5 | 2011-04-22 12:09:36 -0500 | [diff] [blame] | 447 | |
Jeff Layton | faa65f0 | 2012-12-03 06:05:29 -0500 | [diff] [blame] | 448 | out_key_put: |
| 449 | key_put(sidkey); |
| 450 | out_revert_creds: |
| 451 | revert_creds(saved_cred); |
| 452 | kfree(sidstr); |
| 453 | |
| 454 | /* |
| 455 | * Note that we return 0 here unconditionally. If the mapping |
Ronnie Sahlberg | 8401e93 | 2020-12-12 13:40:50 -0600 | [diff] [blame] | 456 | * fails then we just fall back to using the ctx->linux_uid/linux_gid. |
Jeff Layton | faa65f0 | 2012-12-03 06:05:29 -0500 | [diff] [blame] | 457 | */ |
Steve French | 3514de3 | 2016-10-13 19:06:23 -0500 | [diff] [blame] | 458 | got_valid_id: |
Qiujun Huang | f2d6793 | 2020-03-04 15:42:51 +0800 | [diff] [blame] | 459 | rc = 0; |
Jeff Layton | faa65f0 | 2012-12-03 06:05:29 -0500 | [diff] [blame] | 460 | if (sidtype == SIDOWNER) |
| 461 | fattr->cf_uid = fuid; |
| 462 | else |
| 463 | fattr->cf_gid = fgid; |
Qiujun Huang | f2d6793 | 2020-03-04 15:42:51 +0800 | [diff] [blame] | 464 | return rc; |
Shirish Pargaonkar | 9409ae5 | 2011-04-22 12:09:36 -0500 | [diff] [blame] | 465 | } |
| 466 | |
Shirish Pargaonkar | 4d79dba | 2011-04-27 23:34:35 -0500 | [diff] [blame] | 467 | int |
| 468 | init_cifs_idmap(void) |
| 469 | { |
| 470 | struct cred *cred; |
| 471 | struct key *keyring; |
| 472 | int ret; |
| 473 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 474 | cifs_dbg(FYI, "Registering the %s key type\n", |
| 475 | cifs_idmap_key_type.name); |
Shirish Pargaonkar | 4d79dba | 2011-04-27 23:34:35 -0500 | [diff] [blame] | 476 | |
| 477 | /* create an override credential set with a special thread keyring in |
| 478 | * which requests are cached |
| 479 | * |
| 480 | * this is used to prevent malicious redirections from being installed |
| 481 | * with add_key(). |
| 482 | */ |
| 483 | cred = prepare_kernel_cred(NULL); |
| 484 | if (!cred) |
| 485 | return -ENOMEM; |
| 486 | |
Eric W. Biederman | 8e3028b | 2013-02-06 00:21:22 -0800 | [diff] [blame] | 487 | keyring = keyring_alloc(".cifs_idmap", |
| 488 | GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, cred, |
Linus Torvalds | 028db3e | 2019-07-10 18:43:43 -0700 | [diff] [blame] | 489 | (KEY_POS_ALL & ~KEY_POS_SETATTR) | |
| 490 | KEY_USR_VIEW | KEY_USR_READ, |
David Howells | 5ac7eac | 2016-04-06 16:14:24 +0100 | [diff] [blame] | 491 | KEY_ALLOC_NOT_IN_QUOTA, NULL, NULL); |
Shirish Pargaonkar | 4d79dba | 2011-04-27 23:34:35 -0500 | [diff] [blame] | 492 | if (IS_ERR(keyring)) { |
| 493 | ret = PTR_ERR(keyring); |
| 494 | goto failed_put_cred; |
| 495 | } |
| 496 | |
Shirish Pargaonkar | 4d79dba | 2011-04-27 23:34:35 -0500 | [diff] [blame] | 497 | ret = register_key_type(&cifs_idmap_key_type); |
| 498 | if (ret < 0) |
| 499 | goto failed_put_key; |
| 500 | |
| 501 | /* instruct request_key() to use this special keyring as a cache for |
| 502 | * the results it looks up */ |
David Howells | 700920e | 2012-01-18 15:31:45 +0000 | [diff] [blame] | 503 | set_bit(KEY_FLAG_ROOT_CAN_CLEAR, &keyring->flags); |
Shirish Pargaonkar | 4d79dba | 2011-04-27 23:34:35 -0500 | [diff] [blame] | 504 | cred->thread_keyring = keyring; |
| 505 | cred->jit_keyring = KEY_REQKEY_DEFL_THREAD_KEYRING; |
| 506 | root_cred = cred; |
| 507 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 508 | cifs_dbg(FYI, "cifs idmap keyring: %d\n", key_serial(keyring)); |
Shirish Pargaonkar | 4d79dba | 2011-04-27 23:34:35 -0500 | [diff] [blame] | 509 | return 0; |
| 510 | |
| 511 | failed_put_key: |
| 512 | key_put(keyring); |
| 513 | failed_put_cred: |
| 514 | put_cred(cred); |
| 515 | return ret; |
| 516 | } |
| 517 | |
| 518 | void |
| 519 | exit_cifs_idmap(void) |
| 520 | { |
| 521 | key_revoke(root_cred->thread_keyring); |
| 522 | unregister_key_type(&cifs_idmap_key_type); |
| 523 | put_cred(root_cred); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 524 | cifs_dbg(FYI, "Unregistered %s key type\n", cifs_idmap_key_type.name); |
Shirish Pargaonkar | 4d79dba | 2011-04-27 23:34:35 -0500 | [diff] [blame] | 525 | } |
| 526 | |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 527 | /* copy ntsd, owner sid, and group sid from a security descriptor to another */ |
Shyam Prasad N | bc3e9dd | 2021-02-18 13:03:23 +0000 | [diff] [blame] | 528 | static __u32 copy_sec_desc(const struct cifs_ntsd *pntsd, |
| 529 | struct cifs_ntsd *pnntsd, |
| 530 | __u32 sidsoffset, |
| 531 | struct cifs_sid *pownersid, |
| 532 | struct cifs_sid *pgrpsid) |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 533 | { |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 534 | struct cifs_sid *owner_sid_ptr, *group_sid_ptr; |
| 535 | struct cifs_sid *nowner_sid_ptr, *ngroup_sid_ptr; |
| 536 | |
| 537 | /* copy security descriptor control portion */ |
| 538 | pnntsd->revision = pntsd->revision; |
| 539 | pnntsd->type = pntsd->type; |
| 540 | pnntsd->dacloffset = cpu_to_le32(sizeof(struct cifs_ntsd)); |
| 541 | pnntsd->sacloffset = 0; |
| 542 | pnntsd->osidoffset = cpu_to_le32(sidsoffset); |
| 543 | pnntsd->gsidoffset = cpu_to_le32(sidsoffset + sizeof(struct cifs_sid)); |
| 544 | |
| 545 | /* copy owner sid */ |
Shyam Prasad N | bc3e9dd | 2021-02-18 13:03:23 +0000 | [diff] [blame] | 546 | if (pownersid) |
| 547 | owner_sid_ptr = pownersid; |
| 548 | else |
| 549 | owner_sid_ptr = (struct cifs_sid *)((char *)pntsd + |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 550 | le32_to_cpu(pntsd->osidoffset)); |
| 551 | nowner_sid_ptr = (struct cifs_sid *)((char *)pnntsd + sidsoffset); |
Jeff Layton | 36960e4 | 2012-11-03 09:37:28 -0400 | [diff] [blame] | 552 | cifs_copy_sid(nowner_sid_ptr, owner_sid_ptr); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 553 | |
| 554 | /* copy group sid */ |
Shyam Prasad N | bc3e9dd | 2021-02-18 13:03:23 +0000 | [diff] [blame] | 555 | if (pgrpsid) |
| 556 | group_sid_ptr = pgrpsid; |
| 557 | else |
| 558 | group_sid_ptr = (struct cifs_sid *)((char *)pntsd + |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 559 | le32_to_cpu(pntsd->gsidoffset)); |
| 560 | ngroup_sid_ptr = (struct cifs_sid *)((char *)pnntsd + sidsoffset + |
| 561 | sizeof(struct cifs_sid)); |
Jeff Layton | 36960e4 | 2012-11-03 09:37:28 -0400 | [diff] [blame] | 562 | cifs_copy_sid(ngroup_sid_ptr, group_sid_ptr); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 563 | |
Shyam Prasad N | bc3e9dd | 2021-02-18 13:03:23 +0000 | [diff] [blame] | 564 | return sidsoffset + (2 * sizeof(struct cifs_sid)); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 568 | /* |
| 569 | change posix mode to reflect permissions |
| 570 | pmode is the existing mode (we only want to overwrite part of this |
| 571 | bits to set can be: S_IRWXU, S_IRWXG or S_IRWXO ie 00700 or 00070 or 00007 |
| 572 | */ |
Al Viro | 9b5e685 | 2007-12-05 08:24:38 +0000 | [diff] [blame] | 573 | static void access_flags_to_mode(__le32 ace_flags, int type, umode_t *pmode, |
Shyam Prasad N | 0f22053 | 2020-08-17 03:23:12 -0700 | [diff] [blame] | 574 | umode_t *pdenied, umode_t mask) |
Steve French | 4879b44 | 2007-10-19 21:57:39 +0000 | [diff] [blame] | 575 | { |
Al Viro | 9b5e685 | 2007-12-05 08:24:38 +0000 | [diff] [blame] | 576 | __u32 flags = le32_to_cpu(ace_flags); |
Shyam Prasad N | 0f22053 | 2020-08-17 03:23:12 -0700 | [diff] [blame] | 577 | /* |
| 578 | * Do not assume "preferred" or "canonical" order. |
| 579 | * The first DENY or ALLOW ACE which matches perfectly is |
| 580 | * the permission to be used. Once allowed or denied, same |
| 581 | * permission in later ACEs do not matter. |
| 582 | */ |
Steve French | 15b0395 | 2007-11-08 17:57:40 +0000 | [diff] [blame] | 583 | |
Shyam Prasad N | 0f22053 | 2020-08-17 03:23:12 -0700 | [diff] [blame] | 584 | /* If not already allowed, deny these bits */ |
Steve French | 15b0395 | 2007-11-08 17:57:40 +0000 | [diff] [blame] | 585 | if (type == ACCESS_DENIED) { |
Shyam Prasad N | 0f22053 | 2020-08-17 03:23:12 -0700 | [diff] [blame] | 586 | if (flags & GENERIC_ALL && |
| 587 | !(*pmode & mask & 0777)) |
| 588 | *pdenied |= mask & 0777; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 589 | |
Shyam Prasad N | 0f22053 | 2020-08-17 03:23:12 -0700 | [diff] [blame] | 590 | if (((flags & GENERIC_WRITE) || |
| 591 | ((flags & FILE_WRITE_RIGHTS) == FILE_WRITE_RIGHTS)) && |
| 592 | !(*pmode & mask & 0222)) |
| 593 | *pdenied |= mask & 0222; |
| 594 | |
| 595 | if (((flags & GENERIC_READ) || |
| 596 | ((flags & FILE_READ_RIGHTS) == FILE_READ_RIGHTS)) && |
| 597 | !(*pmode & mask & 0444)) |
| 598 | *pdenied |= mask & 0444; |
| 599 | |
| 600 | if (((flags & GENERIC_EXECUTE) || |
| 601 | ((flags & FILE_EXEC_RIGHTS) == FILE_EXEC_RIGHTS)) && |
| 602 | !(*pmode & mask & 0111)) |
| 603 | *pdenied |= mask & 0111; |
| 604 | |
Steve French | 15b0395 | 2007-11-08 17:57:40 +0000 | [diff] [blame] | 605 | return; |
| 606 | } else if (type != ACCESS_ALLOWED) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 607 | cifs_dbg(VFS, "unknown access control type %d\n", type); |
Steve French | 15b0395 | 2007-11-08 17:57:40 +0000 | [diff] [blame] | 608 | return; |
| 609 | } |
| 610 | /* else ACCESS_ALLOWED type */ |
Steve French | 44093ca | 2007-10-23 21:22:55 +0000 | [diff] [blame] | 611 | |
Shyam Prasad N | 0f22053 | 2020-08-17 03:23:12 -0700 | [diff] [blame] | 612 | if ((flags & GENERIC_ALL) && |
| 613 | !(*pdenied & mask & 0777)) { |
| 614 | *pmode |= mask & 0777; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 615 | cifs_dbg(NOISY, "all perms\n"); |
Steve French | d61e580 | 2007-10-26 04:32:43 +0000 | [diff] [blame] | 616 | return; |
| 617 | } |
Shyam Prasad N | 0f22053 | 2020-08-17 03:23:12 -0700 | [diff] [blame] | 618 | |
| 619 | if (((flags & GENERIC_WRITE) || |
| 620 | ((flags & FILE_WRITE_RIGHTS) == FILE_WRITE_RIGHTS)) && |
| 621 | !(*pdenied & mask & 0222)) |
| 622 | *pmode |= mask & 0222; |
| 623 | |
| 624 | if (((flags & GENERIC_READ) || |
| 625 | ((flags & FILE_READ_RIGHTS) == FILE_READ_RIGHTS)) && |
| 626 | !(*pdenied & mask & 0444)) |
| 627 | *pmode |= mask & 0444; |
| 628 | |
| 629 | if (((flags & GENERIC_EXECUTE) || |
| 630 | ((flags & FILE_EXEC_RIGHTS) == FILE_EXEC_RIGHTS)) && |
| 631 | !(*pdenied & mask & 0111)) |
| 632 | *pmode |= mask & 0111; |
Steve French | d61e580 | 2007-10-26 04:32:43 +0000 | [diff] [blame] | 633 | |
Shyam Prasad N | f2156d3 | 2020-11-09 06:12:49 -0800 | [diff] [blame] | 634 | /* If DELETE_CHILD is set only on an owner ACE, set sticky bit */ |
| 635 | if (flags & FILE_DELETE_CHILD) { |
| 636 | if (mask == ACL_OWNER_MASK) { |
| 637 | if (!(*pdenied & 01000)) |
| 638 | *pmode |= 01000; |
| 639 | } else if (!(*pdenied & 01000)) { |
| 640 | *pmode &= ~01000; |
| 641 | *pdenied |= 01000; |
| 642 | } |
| 643 | } |
| 644 | |
Frank Sorenson | f52aa79 | 2020-02-12 15:31:48 -0600 | [diff] [blame] | 645 | cifs_dbg(NOISY, "access flags 0x%x mode now %04o\n", flags, *pmode); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 646 | return; |
| 647 | } |
| 648 | |
Steve French | ce06c9f | 2007-11-08 21:12:01 +0000 | [diff] [blame] | 649 | /* |
| 650 | Generate access flags to reflect permissions mode is the existing mode. |
| 651 | This function is called for every ACE in the DACL whose SID matches |
| 652 | with either owner or group or everyone. |
| 653 | */ |
| 654 | |
| 655 | static void mode_to_access_flags(umode_t mode, umode_t bits_to_use, |
| 656 | __u32 *pace_flags) |
| 657 | { |
| 658 | /* reset access mask */ |
| 659 | *pace_flags = 0x0; |
| 660 | |
| 661 | /* bits to use are either S_IRWXU or S_IRWXG or S_IRWXO */ |
| 662 | mode &= bits_to_use; |
| 663 | |
| 664 | /* check for R/W/X UGO since we do not know whose flags |
| 665 | is this but we have cleared all the bits sans RWX for |
| 666 | either user or group or other as per bits_to_use */ |
| 667 | if (mode & S_IRUGO) |
| 668 | *pace_flags |= SET_FILE_READ_RIGHTS; |
| 669 | if (mode & S_IWUGO) |
| 670 | *pace_flags |= SET_FILE_WRITE_RIGHTS; |
| 671 | if (mode & S_IXUGO) |
| 672 | *pace_flags |= SET_FILE_EXEC_RIGHTS; |
| 673 | |
Frank Sorenson | f52aa79 | 2020-02-12 15:31:48 -0600 | [diff] [blame] | 674 | cifs_dbg(NOISY, "mode: %04o, access flags now 0x%x\n", |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 675 | mode, *pace_flags); |
Steve French | ce06c9f | 2007-11-08 21:12:01 +0000 | [diff] [blame] | 676 | return; |
| 677 | } |
| 678 | |
Shyam Prasad N | bc3e9dd | 2021-02-18 13:03:23 +0000 | [diff] [blame] | 679 | static __u16 cifs_copy_ace(struct cifs_ace *dst, struct cifs_ace *src, struct cifs_sid *psid) |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 680 | { |
| 681 | __u16 size = 1 + 1 + 2 + 4; |
| 682 | |
| 683 | dst->type = src->type; |
| 684 | dst->flags = src->flags; |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 685 | dst->access_req = src->access_req; |
Shyam Prasad N | bc3e9dd | 2021-02-18 13:03:23 +0000 | [diff] [blame] | 686 | |
| 687 | /* Check if there's a replacement sid specified */ |
| 688 | if (psid) |
| 689 | size += cifs_copy_sid(&dst->sid, psid); |
| 690 | else |
| 691 | size += cifs_copy_sid(&dst->sid, &src->sid); |
| 692 | |
| 693 | dst->size = cpu_to_le16(size); |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 694 | |
| 695 | return size; |
| 696 | } |
| 697 | |
Al Viro | 2b210ad | 2008-03-29 03:09:18 +0000 | [diff] [blame] | 698 | static __u16 fill_ace_for_sid(struct cifs_ace *pntace, |
Shyam Prasad N | f2156d3 | 2020-11-09 06:12:49 -0800 | [diff] [blame] | 699 | const struct cifs_sid *psid, __u64 nmode, |
| 700 | umode_t bits, __u8 access_type, |
| 701 | bool allow_delete_child) |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 702 | { |
| 703 | int i; |
| 704 | __u16 size = 0; |
| 705 | __u32 access_req = 0; |
| 706 | |
Shyam Prasad N | 0f22053 | 2020-08-17 03:23:12 -0700 | [diff] [blame] | 707 | pntace->type = access_type; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 708 | pntace->flags = 0x0; |
| 709 | mode_to_access_flags(nmode, bits, &access_req); |
Shyam Prasad N | f2156d3 | 2020-11-09 06:12:49 -0800 | [diff] [blame] | 710 | |
| 711 | if (access_type == ACCESS_ALLOWED && allow_delete_child) |
| 712 | access_req |= FILE_DELETE_CHILD; |
| 713 | |
Shyam Prasad N | 0f22053 | 2020-08-17 03:23:12 -0700 | [diff] [blame] | 714 | if (access_type == ACCESS_ALLOWED && !access_req) |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 715 | access_req = SET_MINIMUM_RIGHTS; |
Shyam Prasad N | 0f22053 | 2020-08-17 03:23:12 -0700 | [diff] [blame] | 716 | else if (access_type == ACCESS_DENIED) |
| 717 | access_req &= ~SET_MINIMUM_RIGHTS; |
Shyam Prasad N | f2156d3 | 2020-11-09 06:12:49 -0800 | [diff] [blame] | 718 | |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 719 | pntace->access_req = cpu_to_le32(access_req); |
| 720 | |
| 721 | pntace->sid.revision = psid->revision; |
| 722 | pntace->sid.num_subauth = psid->num_subauth; |
Jeff Layton | 852e229 | 2012-11-25 08:00:36 -0500 | [diff] [blame] | 723 | for (i = 0; i < NUM_AUTHS; i++) |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 724 | pntace->sid.authority[i] = psid->authority[i]; |
| 725 | for (i = 0; i < psid->num_subauth; i++) |
| 726 | pntace->sid.sub_auth[i] = psid->sub_auth[i]; |
| 727 | |
| 728 | size = 1 + 1 + 2 + 4 + 1 + 1 + 6 + (psid->num_subauth * 4); |
| 729 | pntace->size = cpu_to_le16(size); |
| 730 | |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 731 | return size; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 732 | } |
| 733 | |
Steve French | 297647c | 2007-10-12 04:11:59 +0000 | [diff] [blame] | 734 | |
Steve French | 953f868 | 2007-10-31 04:54:42 +0000 | [diff] [blame] | 735 | #ifdef CONFIG_CIFS_DEBUG2 |
| 736 | static void dump_ace(struct cifs_ace *pace, char *end_of_acl) |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 737 | { |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 738 | int num_subauth; |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 739 | |
| 740 | /* validate that we do not go past end of acl */ |
Steve French | 297647c | 2007-10-12 04:11:59 +0000 | [diff] [blame] | 741 | |
Steve French | 44093ca | 2007-10-23 21:22:55 +0000 | [diff] [blame] | 742 | if (le16_to_cpu(pace->size) < 16) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 743 | cifs_dbg(VFS, "ACE too small %d\n", le16_to_cpu(pace->size)); |
Steve French | 44093ca | 2007-10-23 21:22:55 +0000 | [diff] [blame] | 744 | return; |
| 745 | } |
| 746 | |
| 747 | if (end_of_acl < (char *)pace + le16_to_cpu(pace->size)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 748 | cifs_dbg(VFS, "ACL too small to parse ACE\n"); |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 749 | return; |
Steve French | 44093ca | 2007-10-23 21:22:55 +0000 | [diff] [blame] | 750 | } |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 751 | |
Steve French | 44093ca | 2007-10-23 21:22:55 +0000 | [diff] [blame] | 752 | num_subauth = pace->sid.num_subauth; |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 753 | if (num_subauth) { |
Steve French | 8f18c13 | 2007-10-12 18:54:12 +0000 | [diff] [blame] | 754 | int i; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 755 | cifs_dbg(FYI, "ACE revision %d num_auth %d type %d flags %d size %d\n", |
| 756 | pace->sid.revision, pace->sid.num_subauth, pace->type, |
| 757 | pace->flags, le16_to_cpu(pace->size)); |
Steve French | d12fd12 | 2007-10-03 19:43:19 +0000 | [diff] [blame] | 758 | for (i = 0; i < num_subauth; ++i) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 759 | cifs_dbg(FYI, "ACE sub_auth[%d]: 0x%x\n", |
| 760 | i, le32_to_cpu(pace->sid.sub_auth[i])); |
Steve French | d12fd12 | 2007-10-03 19:43:19 +0000 | [diff] [blame] | 761 | } |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 762 | |
Steve French | d12fd12 | 2007-10-03 19:43:19 +0000 | [diff] [blame] | 763 | /* BB add length check to make sure that we do not have huge |
| 764 | num auths and therefore go off the end */ |
Steve French | d12fd12 | 2007-10-03 19:43:19 +0000 | [diff] [blame] | 765 | } |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 766 | |
Steve French | d12fd12 | 2007-10-03 19:43:19 +0000 | [diff] [blame] | 767 | return; |
| 768 | } |
Steve French | 953f868 | 2007-10-31 04:54:42 +0000 | [diff] [blame] | 769 | #endif |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 770 | |
Steve French | a750e77 | 2007-10-17 22:50:39 +0000 | [diff] [blame] | 771 | static void parse_dacl(struct cifs_acl *pdacl, char *end_of_acl, |
Steve French | d61e580 | 2007-10-26 04:32:43 +0000 | [diff] [blame] | 772 | struct cifs_sid *pownersid, struct cifs_sid *pgrpsid, |
Steve French | e2f8fbf | 2019-07-19 06:30:07 +0000 | [diff] [blame] | 773 | struct cifs_fattr *fattr, bool mode_from_special_sid) |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 774 | { |
| 775 | int i; |
| 776 | int num_aces = 0; |
| 777 | int acl_size; |
| 778 | char *acl_base; |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 779 | struct cifs_ace **ppace; |
| 780 | |
| 781 | /* BB need to add parm so we can store the SID BB */ |
| 782 | |
Steve French | 2b83457 | 2007-11-25 10:01:00 +0000 | [diff] [blame] | 783 | if (!pdacl) { |
| 784 | /* no DACL in the security descriptor, set |
| 785 | all the permissions for user/group/other */ |
Shyam Prasad N | 0f22053 | 2020-08-17 03:23:12 -0700 | [diff] [blame] | 786 | fattr->cf_mode |= 0777; |
Steve French | 2b83457 | 2007-11-25 10:01:00 +0000 | [diff] [blame] | 787 | return; |
| 788 | } |
| 789 | |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 790 | /* validate that we do not go past end of acl */ |
Steve French | af6f461 | 2007-10-16 18:40:37 +0000 | [diff] [blame] | 791 | if (end_of_acl < (char *)pdacl + le16_to_cpu(pdacl->size)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 792 | cifs_dbg(VFS, "ACL too small to parse DACL\n"); |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 793 | return; |
| 794 | } |
| 795 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 796 | cifs_dbg(NOISY, "DACL revision %d size %d num aces %d\n", |
| 797 | le16_to_cpu(pdacl->revision), le16_to_cpu(pdacl->size), |
| 798 | le32_to_cpu(pdacl->num_aces)); |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 799 | |
Steve French | 7505e05 | 2007-11-01 18:03:01 +0000 | [diff] [blame] | 800 | /* reset rwx permissions for user/group/other. |
| 801 | Also, if num_aces is 0 i.e. DACL has no ACEs, |
| 802 | user/group/other have no permissions */ |
Shyam Prasad N | 0f22053 | 2020-08-17 03:23:12 -0700 | [diff] [blame] | 803 | fattr->cf_mode &= ~(0777); |
Steve French | 7505e05 | 2007-11-01 18:03:01 +0000 | [diff] [blame] | 804 | |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 805 | acl_base = (char *)pdacl; |
| 806 | acl_size = sizeof(struct cifs_acl); |
| 807 | |
Steve French | adbc035 | 2007-10-17 02:12:46 +0000 | [diff] [blame] | 808 | num_aces = le32_to_cpu(pdacl->num_aces); |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 809 | if (num_aces > 0) { |
Shyam Prasad N | 0f22053 | 2020-08-17 03:23:12 -0700 | [diff] [blame] | 810 | umode_t denied_mode = 0; |
Steve French | 15b0395 | 2007-11-08 17:57:40 +0000 | [diff] [blame] | 811 | |
Dan Carpenter | 7250170 | 2012-01-11 10:46:27 +0300 | [diff] [blame] | 812 | if (num_aces > ULONG_MAX / sizeof(struct cifs_ace *)) |
| 813 | return; |
Kees Cook | 6da2ec5 | 2018-06-12 13:55:00 -0700 | [diff] [blame] | 814 | ppace = kmalloc_array(num_aces, sizeof(struct cifs_ace *), |
| 815 | GFP_KERNEL); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 816 | if (!ppace) |
Stanislav Fomichev | 8132b65 | 2011-02-06 02:05:28 +0300 | [diff] [blame] | 817 | return; |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 818 | |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 819 | for (i = 0; i < num_aces; ++i) { |
Steve French | 44093ca | 2007-10-23 21:22:55 +0000 | [diff] [blame] | 820 | ppace[i] = (struct cifs_ace *) (acl_base + acl_size); |
Steve French | 953f868 | 2007-10-31 04:54:42 +0000 | [diff] [blame] | 821 | #ifdef CONFIG_CIFS_DEBUG2 |
| 822 | dump_ace(ppace[i], end_of_acl); |
| 823 | #endif |
Steve French | e2f8fbf | 2019-07-19 06:30:07 +0000 | [diff] [blame] | 824 | if (mode_from_special_sid && |
| 825 | (compare_sids(&(ppace[i]->sid), |
| 826 | &sid_unix_NFS_mode) == 0)) { |
| 827 | /* |
| 828 | * Full permissions are: |
| 829 | * 07777 = S_ISUID | S_ISGID | S_ISVTX | |
| 830 | * S_IRWXU | S_IRWXG | S_IRWXO |
| 831 | */ |
| 832 | fattr->cf_mode &= ~07777; |
| 833 | fattr->cf_mode |= |
| 834 | le32_to_cpu(ppace[i]->sid.sub_auth[2]); |
| 835 | break; |
Shyam Prasad N | 0f22053 | 2020-08-17 03:23:12 -0700 | [diff] [blame] | 836 | } else { |
| 837 | if (compare_sids(&(ppace[i]->sid), pownersid) == 0) { |
| 838 | access_flags_to_mode(ppace[i]->access_req, |
| 839 | ppace[i]->type, |
| 840 | &fattr->cf_mode, |
| 841 | &denied_mode, |
| 842 | ACL_OWNER_MASK); |
| 843 | } else if (compare_sids(&(ppace[i]->sid), pgrpsid) == 0) { |
| 844 | access_flags_to_mode(ppace[i]->access_req, |
| 845 | ppace[i]->type, |
| 846 | &fattr->cf_mode, |
| 847 | &denied_mode, |
| 848 | ACL_GROUP_MASK); |
| 849 | } else if ((compare_sids(&(ppace[i]->sid), &sid_everyone) == 0) || |
| 850 | (compare_sids(&(ppace[i]->sid), &sid_authusers) == 0)) { |
| 851 | access_flags_to_mode(ppace[i]->access_req, |
| 852 | ppace[i]->type, |
| 853 | &fattr->cf_mode, |
| 854 | &denied_mode, |
| 855 | ACL_EVERYONE_MASK); |
| 856 | } |
| 857 | } |
Shirish Pargaonkar | 2fbc2f1 | 2010-12-06 14:56:46 -0600 | [diff] [blame] | 858 | |
Shirish Pargaonkar | e01b640 | 2007-10-30 04:45:14 +0000 | [diff] [blame] | 859 | |
Steve French | 44093ca | 2007-10-23 21:22:55 +0000 | [diff] [blame] | 860 | /* memcpy((void *)(&(cifscred->aces[i])), |
Steve French | d12fd12 | 2007-10-03 19:43:19 +0000 | [diff] [blame] | 861 | (void *)ppace[i], |
| 862 | sizeof(struct cifs_ace)); */ |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 863 | |
Steve French | 44093ca | 2007-10-23 21:22:55 +0000 | [diff] [blame] | 864 | acl_base = (char *)ppace[i]; |
| 865 | acl_size = le16_to_cpu(ppace[i]->size); |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | kfree(ppace); |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | return; |
| 872 | } |
| 873 | |
Steve French | 643fbce | 2020-01-16 19:55:33 -0600 | [diff] [blame] | 874 | unsigned int setup_authusers_ACE(struct cifs_ace *pntace) |
| 875 | { |
| 876 | int i; |
| 877 | unsigned int ace_size = 20; |
| 878 | |
| 879 | pntace->type = ACCESS_ALLOWED_ACE_TYPE; |
| 880 | pntace->flags = 0x0; |
| 881 | pntace->access_req = cpu_to_le32(GENERIC_ALL); |
| 882 | pntace->sid.num_subauth = 1; |
| 883 | pntace->sid.revision = 1; |
| 884 | for (i = 0; i < NUM_AUTHS; i++) |
| 885 | pntace->sid.authority[i] = sid_authusers.authority[i]; |
| 886 | |
| 887 | pntace->sid.sub_auth[0] = sid_authusers.sub_auth[0]; |
| 888 | |
| 889 | /* size = 1 + 1 + 2 + 4 + 1 + 1 + 6 + (psid->num_subauth*4) */ |
| 890 | pntace->size = cpu_to_le16(ace_size); |
| 891 | return ace_size; |
| 892 | } |
| 893 | |
Steve French | fdef665 | 2019-12-06 02:02:38 -0600 | [diff] [blame] | 894 | /* |
| 895 | * Fill in the special SID based on the mode. See |
Alexander A. Klimov | cba22b1 | 2020-06-27 12:31:25 +0200 | [diff] [blame] | 896 | * https://technet.microsoft.com/en-us/library/hh509017(v=ws.10).aspx |
Steve French | fdef665 | 2019-12-06 02:02:38 -0600 | [diff] [blame] | 897 | */ |
| 898 | unsigned int setup_special_mode_ACE(struct cifs_ace *pntace, __u64 nmode) |
| 899 | { |
| 900 | int i; |
| 901 | unsigned int ace_size = 28; |
| 902 | |
| 903 | pntace->type = ACCESS_DENIED_ACE_TYPE; |
| 904 | pntace->flags = 0x0; |
| 905 | pntace->access_req = 0; |
| 906 | pntace->sid.num_subauth = 3; |
| 907 | pntace->sid.revision = 1; |
| 908 | for (i = 0; i < NUM_AUTHS; i++) |
| 909 | pntace->sid.authority[i] = sid_unix_NFS_mode.authority[i]; |
| 910 | |
| 911 | pntace->sid.sub_auth[0] = sid_unix_NFS_mode.sub_auth[0]; |
| 912 | pntace->sid.sub_auth[1] = sid_unix_NFS_mode.sub_auth[1]; |
| 913 | pntace->sid.sub_auth[2] = cpu_to_le32(nmode & 07777); |
| 914 | |
| 915 | /* size = 1 + 1 + 2 + 4 + 1 + 1 + 6 + (psid->num_subauth*4) */ |
| 916 | pntace->size = cpu_to_le16(ace_size); |
| 917 | return ace_size; |
| 918 | } |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 919 | |
Steve French | 975221e | 2020-06-12 09:25:21 -0500 | [diff] [blame] | 920 | unsigned int setup_special_user_owner_ACE(struct cifs_ace *pntace) |
| 921 | { |
| 922 | int i; |
| 923 | unsigned int ace_size = 28; |
| 924 | |
| 925 | pntace->type = ACCESS_ALLOWED_ACE_TYPE; |
| 926 | pntace->flags = 0x0; |
| 927 | pntace->access_req = cpu_to_le32(GENERIC_ALL); |
| 928 | pntace->sid.num_subauth = 3; |
| 929 | pntace->sid.revision = 1; |
| 930 | for (i = 0; i < NUM_AUTHS; i++) |
| 931 | pntace->sid.authority[i] = sid_unix_NFS_users.authority[i]; |
| 932 | |
| 933 | pntace->sid.sub_auth[0] = sid_unix_NFS_users.sub_auth[0]; |
| 934 | pntace->sid.sub_auth[1] = sid_unix_NFS_users.sub_auth[1]; |
| 935 | pntace->sid.sub_auth[2] = cpu_to_le32(current_fsgid().val); |
| 936 | |
| 937 | /* size = 1 + 1 + 2 + 4 + 1 + 1 + 6 + (psid->num_subauth*4) */ |
| 938 | pntace->size = cpu_to_le16(ace_size); |
| 939 | return ace_size; |
| 940 | } |
| 941 | |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 942 | static void populate_new_aces(char *nacl_base, |
| 943 | struct cifs_sid *pownersid, |
| 944 | struct cifs_sid *pgrpsid, |
| 945 | __u64 *pnmode, u32 *pnum_aces, u16 *pnsize, |
| 946 | bool modefromsid) |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 947 | { |
Shyam Prasad N | 0f22053 | 2020-08-17 03:23:12 -0700 | [diff] [blame] | 948 | __u64 nmode; |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 949 | u32 num_aces = 0; |
| 950 | u16 nsize = 0; |
Shyam Prasad N | 0f22053 | 2020-08-17 03:23:12 -0700 | [diff] [blame] | 951 | __u64 user_mode; |
| 952 | __u64 group_mode; |
| 953 | __u64 other_mode; |
| 954 | __u64 deny_user_mode = 0; |
| 955 | __u64 deny_group_mode = 0; |
Shyam Prasad N | f2156d3 | 2020-11-09 06:12:49 -0800 | [diff] [blame] | 956 | bool sticky_set = false; |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 957 | struct cifs_ace *pnntace = NULL; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 958 | |
Shyam Prasad N | 0f22053 | 2020-08-17 03:23:12 -0700 | [diff] [blame] | 959 | nmode = *pnmode; |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 960 | num_aces = *pnum_aces; |
| 961 | nsize = *pnsize; |
Shyam Prasad N | 0f22053 | 2020-08-17 03:23:12 -0700 | [diff] [blame] | 962 | |
Steve French | 2244217 | 2019-07-19 08:15:55 +0000 | [diff] [blame] | 963 | if (modefromsid) { |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 964 | pnntace = (struct cifs_ace *) (nacl_base + nsize); |
| 965 | nsize += setup_special_mode_ACE(pnntace, nmode); |
Aurelien Aptel | e37a02c | 2019-09-17 01:47:27 +0200 | [diff] [blame] | 966 | num_aces++; |
Shyam Prasad N | 0f22053 | 2020-08-17 03:23:12 -0700 | [diff] [blame] | 967 | goto set_size; |
Aurelien Aptel | e37a02c | 2019-09-17 01:47:27 +0200 | [diff] [blame] | 968 | } |
Steve French | 2244217 | 2019-07-19 08:15:55 +0000 | [diff] [blame] | 969 | |
Shyam Prasad N | 0f22053 | 2020-08-17 03:23:12 -0700 | [diff] [blame] | 970 | /* |
| 971 | * We'll try to keep the mode as requested by the user. |
| 972 | * But in cases where we cannot meaningfully convert that |
| 973 | * into ACL, return back the updated mode, so that it is |
| 974 | * updated in the inode. |
| 975 | */ |
| 976 | |
| 977 | if (!memcmp(pownersid, pgrpsid, sizeof(struct cifs_sid))) { |
| 978 | /* |
| 979 | * Case when owner and group SIDs are the same. |
| 980 | * Set the more restrictive of the two modes. |
| 981 | */ |
| 982 | user_mode = nmode & (nmode << 3) & 0700; |
| 983 | group_mode = nmode & (nmode >> 3) & 0070; |
| 984 | } else { |
| 985 | user_mode = nmode & 0700; |
| 986 | group_mode = nmode & 0070; |
| 987 | } |
| 988 | |
| 989 | other_mode = nmode & 0007; |
| 990 | |
| 991 | /* We need DENY ACE when the perm is more restrictive than the next sets. */ |
| 992 | deny_user_mode = ~(user_mode) & ((group_mode << 3) | (other_mode << 6)) & 0700; |
| 993 | deny_group_mode = ~(group_mode) & (other_mode << 3) & 0070; |
| 994 | |
| 995 | *pnmode = user_mode | group_mode | other_mode | (nmode & ~0777); |
| 996 | |
Shyam Prasad N | f2156d3 | 2020-11-09 06:12:49 -0800 | [diff] [blame] | 997 | /* This tells if we should allow delete child for group and everyone. */ |
| 998 | if (nmode & 01000) |
| 999 | sticky_set = true; |
| 1000 | |
Shyam Prasad N | 0f22053 | 2020-08-17 03:23:12 -0700 | [diff] [blame] | 1001 | if (deny_user_mode) { |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 1002 | pnntace = (struct cifs_ace *) (nacl_base + nsize); |
| 1003 | nsize += fill_ace_for_sid(pnntace, pownersid, deny_user_mode, |
| 1004 | 0700, ACCESS_DENIED, false); |
Shyam Prasad N | 0f22053 | 2020-08-17 03:23:12 -0700 | [diff] [blame] | 1005 | num_aces++; |
| 1006 | } |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 1007 | |
Shyam Prasad N | 0f22053 | 2020-08-17 03:23:12 -0700 | [diff] [blame] | 1008 | /* Group DENY ACE does not conflict with owner ALLOW ACE. Keep in preferred order*/ |
| 1009 | if (deny_group_mode && !(deny_group_mode & (user_mode >> 3))) { |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 1010 | pnntace = (struct cifs_ace *) (nacl_base + nsize); |
| 1011 | nsize += fill_ace_for_sid(pnntace, pgrpsid, deny_group_mode, |
| 1012 | 0070, ACCESS_DENIED, false); |
Shyam Prasad N | 0f22053 | 2020-08-17 03:23:12 -0700 | [diff] [blame] | 1013 | num_aces++; |
| 1014 | } |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 1015 | |
| 1016 | pnntace = (struct cifs_ace *) (nacl_base + nsize); |
| 1017 | nsize += fill_ace_for_sid(pnntace, pownersid, user_mode, |
| 1018 | 0700, ACCESS_ALLOWED, true); |
Shyam Prasad N | 0f22053 | 2020-08-17 03:23:12 -0700 | [diff] [blame] | 1019 | num_aces++; |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 1020 | |
Shyam Prasad N | 0f22053 | 2020-08-17 03:23:12 -0700 | [diff] [blame] | 1021 | /* Group DENY ACE conflicts with owner ALLOW ACE. So keep it after. */ |
| 1022 | if (deny_group_mode && (deny_group_mode & (user_mode >> 3))) { |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 1023 | pnntace = (struct cifs_ace *) (nacl_base + nsize); |
| 1024 | nsize += fill_ace_for_sid(pnntace, pgrpsid, deny_group_mode, |
| 1025 | 0070, ACCESS_DENIED, false); |
Shyam Prasad N | 0f22053 | 2020-08-17 03:23:12 -0700 | [diff] [blame] | 1026 | num_aces++; |
| 1027 | } |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 1028 | |
| 1029 | pnntace = (struct cifs_ace *) (nacl_base + nsize); |
| 1030 | nsize += fill_ace_for_sid(pnntace, pgrpsid, group_mode, |
| 1031 | 0070, ACCESS_ALLOWED, !sticky_set); |
Aurelien Aptel | e37a02c | 2019-09-17 01:47:27 +0200 | [diff] [blame] | 1032 | num_aces++; |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 1033 | |
| 1034 | pnntace = (struct cifs_ace *) (nacl_base + nsize); |
| 1035 | nsize += fill_ace_for_sid(pnntace, &sid_everyone, other_mode, |
| 1036 | 0007, ACCESS_ALLOWED, !sticky_set); |
Aurelien Aptel | e37a02c | 2019-09-17 01:47:27 +0200 | [diff] [blame] | 1037 | num_aces++; |
| 1038 | |
Shyam Prasad N | 0f22053 | 2020-08-17 03:23:12 -0700 | [diff] [blame] | 1039 | set_size: |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 1040 | *pnum_aces = num_aces; |
| 1041 | *pnsize = nsize; |
| 1042 | } |
| 1043 | |
| 1044 | static __u16 replace_sids_and_copy_aces(struct cifs_acl *pdacl, struct cifs_acl *pndacl, |
| 1045 | struct cifs_sid *pownersid, struct cifs_sid *pgrpsid, |
| 1046 | struct cifs_sid *pnownersid, struct cifs_sid *pngrpsid) |
| 1047 | { |
| 1048 | int i; |
| 1049 | u16 size = 0; |
| 1050 | struct cifs_ace *pntace = NULL; |
| 1051 | char *acl_base = NULL; |
| 1052 | u32 src_num_aces = 0; |
| 1053 | u16 nsize = 0; |
| 1054 | struct cifs_ace *pnntace = NULL; |
| 1055 | char *nacl_base = NULL; |
| 1056 | u16 ace_size = 0; |
| 1057 | |
| 1058 | acl_base = (char *)pdacl; |
| 1059 | size = sizeof(struct cifs_acl); |
| 1060 | src_num_aces = le32_to_cpu(pdacl->num_aces); |
| 1061 | |
| 1062 | nacl_base = (char *)pndacl; |
| 1063 | nsize = sizeof(struct cifs_acl); |
| 1064 | |
| 1065 | /* Go through all the ACEs */ |
| 1066 | for (i = 0; i < src_num_aces; ++i) { |
| 1067 | pntace = (struct cifs_ace *) (acl_base + size); |
| 1068 | pnntace = (struct cifs_ace *) (nacl_base + nsize); |
| 1069 | |
| 1070 | if (pnownersid && compare_sids(&pntace->sid, pownersid) == 0) |
Shyam Prasad N | bc3e9dd | 2021-02-18 13:03:23 +0000 | [diff] [blame] | 1071 | ace_size = cifs_copy_ace(pnntace, pntace, pnownersid); |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 1072 | else if (pngrpsid && compare_sids(&pntace->sid, pgrpsid) == 0) |
Shyam Prasad N | bc3e9dd | 2021-02-18 13:03:23 +0000 | [diff] [blame] | 1073 | ace_size = cifs_copy_ace(pnntace, pntace, pngrpsid); |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 1074 | else |
Shyam Prasad N | bc3e9dd | 2021-02-18 13:03:23 +0000 | [diff] [blame] | 1075 | ace_size = cifs_copy_ace(pnntace, pntace, NULL); |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 1076 | |
| 1077 | size += le16_to_cpu(pntace->size); |
| 1078 | nsize += ace_size; |
| 1079 | } |
| 1080 | |
| 1081 | return nsize; |
| 1082 | } |
| 1083 | |
| 1084 | static int set_chmod_dacl(struct cifs_acl *pdacl, struct cifs_acl *pndacl, |
| 1085 | struct cifs_sid *pownersid, struct cifs_sid *pgrpsid, |
| 1086 | __u64 *pnmode, bool mode_from_sid) |
| 1087 | { |
| 1088 | int i; |
| 1089 | u16 size = 0; |
| 1090 | struct cifs_ace *pntace = NULL; |
| 1091 | char *acl_base = NULL; |
| 1092 | u32 src_num_aces = 0; |
| 1093 | u16 nsize = 0; |
| 1094 | struct cifs_ace *pnntace = NULL; |
| 1095 | char *nacl_base = NULL; |
| 1096 | u32 num_aces = 0; |
| 1097 | __u64 nmode; |
| 1098 | bool new_aces_set = false; |
| 1099 | |
| 1100 | /* Assuming that pndacl and pnmode are never NULL */ |
| 1101 | nmode = *pnmode; |
| 1102 | nacl_base = (char *)pndacl; |
| 1103 | nsize = sizeof(struct cifs_acl); |
| 1104 | |
| 1105 | /* If pdacl is NULL, we don't have a src. Simply populate new ACL. */ |
| 1106 | if (!pdacl) { |
| 1107 | populate_new_aces(nacl_base, |
| 1108 | pownersid, pgrpsid, |
| 1109 | pnmode, &num_aces, &nsize, |
| 1110 | mode_from_sid); |
| 1111 | goto finalize_dacl; |
| 1112 | } |
| 1113 | |
| 1114 | acl_base = (char *)pdacl; |
| 1115 | size = sizeof(struct cifs_acl); |
| 1116 | src_num_aces = le32_to_cpu(pdacl->num_aces); |
| 1117 | |
| 1118 | /* Retain old ACEs which we can retain */ |
| 1119 | for (i = 0; i < src_num_aces; ++i) { |
| 1120 | pntace = (struct cifs_ace *) (acl_base + size); |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 1121 | |
| 1122 | if (!new_aces_set && (pntace->flags & INHERITED_ACE)) { |
| 1123 | /* Place the new ACEs in between existing explicit and inherited */ |
| 1124 | populate_new_aces(nacl_base, |
| 1125 | pownersid, pgrpsid, |
| 1126 | pnmode, &num_aces, &nsize, |
| 1127 | mode_from_sid); |
| 1128 | |
| 1129 | new_aces_set = true; |
| 1130 | } |
| 1131 | |
| 1132 | /* If it's any one of the ACE we're replacing, skip! */ |
Shyam Prasad N | 3bffbe9 | 2021-03-26 10:28:16 +0000 | [diff] [blame] | 1133 | if (((compare_sids(&pntace->sid, &sid_unix_NFS_mode) == 0) || |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 1134 | (compare_sids(&pntace->sid, pownersid) == 0) || |
| 1135 | (compare_sids(&pntace->sid, pgrpsid) == 0) || |
| 1136 | (compare_sids(&pntace->sid, &sid_everyone) == 0) || |
Shyam Prasad N | 5171317 | 2021-03-10 10:22:27 +0000 | [diff] [blame] | 1137 | (compare_sids(&pntace->sid, &sid_authusers) == 0))) { |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 1138 | goto next_ace; |
| 1139 | } |
| 1140 | |
Shyam Prasad N | 5171317 | 2021-03-10 10:22:27 +0000 | [diff] [blame] | 1141 | /* update the pointer to the next ACE to populate*/ |
| 1142 | pnntace = (struct cifs_ace *) (nacl_base + nsize); |
| 1143 | |
Shyam Prasad N | bc3e9dd | 2021-02-18 13:03:23 +0000 | [diff] [blame] | 1144 | nsize += cifs_copy_ace(pnntace, pntace, NULL); |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 1145 | num_aces++; |
| 1146 | |
| 1147 | next_ace: |
Steve French | 23bda5e | 2021-02-22 14:40:43 -0600 | [diff] [blame] | 1148 | size += le16_to_cpu(pntace->size); |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | /* If inherited ACEs are not present, place the new ones at the tail */ |
| 1152 | if (!new_aces_set) { |
| 1153 | populate_new_aces(nacl_base, |
| 1154 | pownersid, pgrpsid, |
| 1155 | pnmode, &num_aces, &nsize, |
| 1156 | mode_from_sid); |
| 1157 | |
| 1158 | new_aces_set = true; |
| 1159 | } |
| 1160 | |
| 1161 | finalize_dacl: |
Aurelien Aptel | e37a02c | 2019-09-17 01:47:27 +0200 | [diff] [blame] | 1162 | pndacl->num_aces = cpu_to_le32(num_aces); |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 1163 | pndacl->size = cpu_to_le16(nsize); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 1164 | |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 1165 | return 0; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 1166 | } |
| 1167 | |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 1168 | static int parse_sid(struct cifs_sid *psid, char *end_of_acl) |
| 1169 | { |
| 1170 | /* BB need to add parm so we can store the SID BB */ |
| 1171 | |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 1172 | /* validate that we do not go past end of ACL - sid must be at least 8 |
| 1173 | bytes long (assuming no sub-auths - e.g. the null SID */ |
| 1174 | if (end_of_acl < (char *)psid + 8) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1175 | cifs_dbg(VFS, "ACL too small to parse SID %p\n", psid); |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 1176 | return -EINVAL; |
| 1177 | } |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 1178 | |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 1179 | #ifdef CONFIG_CIFS_DEBUG2 |
Jeff Layton | fc03d8a | 2012-11-25 08:00:35 -0500 | [diff] [blame] | 1180 | if (psid->num_subauth) { |
Steve French | 8f18c13 | 2007-10-12 18:54:12 +0000 | [diff] [blame] | 1181 | int i; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1182 | cifs_dbg(FYI, "SID revision %d num_auth %d\n", |
| 1183 | psid->revision, psid->num_subauth); |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 1184 | |
Steve French | af6f461 | 2007-10-16 18:40:37 +0000 | [diff] [blame] | 1185 | for (i = 0; i < psid->num_subauth; i++) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1186 | cifs_dbg(FYI, "SID sub_auth[%d]: 0x%x\n", |
| 1187 | i, le32_to_cpu(psid->sub_auth[i])); |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 1188 | } |
| 1189 | |
Steve French | d12fd12 | 2007-10-03 19:43:19 +0000 | [diff] [blame] | 1190 | /* BB add length check to make sure that we do not have huge |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 1191 | num auths and therefore go off the end */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1192 | cifs_dbg(FYI, "RID 0x%x\n", |
| 1193 | le32_to_cpu(psid->sub_auth[psid->num_subauth-1])); |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 1194 | } |
Jeff Layton | fc03d8a | 2012-11-25 08:00:35 -0500 | [diff] [blame] | 1195 | #endif |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 1196 | |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 1197 | return 0; |
| 1198 | } |
| 1199 | |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 1200 | |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 1201 | /* Convert CIFS ACL to POSIX form */ |
Shirish Pargaonkar | 9409ae5 | 2011-04-22 12:09:36 -0500 | [diff] [blame] | 1202 | static int parse_sec_desc(struct cifs_sb_info *cifs_sb, |
Steve French | e2f8fbf | 2019-07-19 06:30:07 +0000 | [diff] [blame] | 1203 | struct cifs_ntsd *pntsd, int acl_len, struct cifs_fattr *fattr, |
| 1204 | bool get_mode_from_special_sid) |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 1205 | { |
Shirish Pargaonkar | 9409ae5 | 2011-04-22 12:09:36 -0500 | [diff] [blame] | 1206 | int rc = 0; |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 1207 | struct cifs_sid *owner_sid_ptr, *group_sid_ptr; |
| 1208 | struct cifs_acl *dacl_ptr; /* no need for SACL ptr */ |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 1209 | char *end_of_acl = ((char *)pntsd) + acl_len; |
Steve French | 7505e05 | 2007-11-01 18:03:01 +0000 | [diff] [blame] | 1210 | __u32 dacloffset; |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 1211 | |
Jeff Layton | 0b8f18e | 2009-07-09 01:46:37 -0400 | [diff] [blame] | 1212 | if (pntsd == NULL) |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 1213 | return -EIO; |
| 1214 | |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 1215 | owner_sid_ptr = (struct cifs_sid *)((char *)pntsd + |
Steve French | af6f461 | 2007-10-16 18:40:37 +0000 | [diff] [blame] | 1216 | le32_to_cpu(pntsd->osidoffset)); |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 1217 | group_sid_ptr = (struct cifs_sid *)((char *)pntsd + |
Steve French | af6f461 | 2007-10-16 18:40:37 +0000 | [diff] [blame] | 1218 | le32_to_cpu(pntsd->gsidoffset)); |
Steve French | 7505e05 | 2007-11-01 18:03:01 +0000 | [diff] [blame] | 1219 | dacloffset = le32_to_cpu(pntsd->dacloffset); |
Steve French | 63d2583 | 2007-11-05 21:46:10 +0000 | [diff] [blame] | 1220 | dacl_ptr = (struct cifs_acl *)((char *)pntsd + dacloffset); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1221 | cifs_dbg(NOISY, "revision %d type 0x%x ooffset 0x%x goffset 0x%x sacloffset 0x%x dacloffset 0x%x\n", |
Steve French | af6f461 | 2007-10-16 18:40:37 +0000 | [diff] [blame] | 1222 | pntsd->revision, pntsd->type, le32_to_cpu(pntsd->osidoffset), |
| 1223 | le32_to_cpu(pntsd->gsidoffset), |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1224 | le32_to_cpu(pntsd->sacloffset), dacloffset); |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 1225 | /* cifs_dump_mem("owner_sid: ", owner_sid_ptr, 64); */ |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 1226 | rc = parse_sid(owner_sid_ptr, end_of_acl); |
Shirish Pargaonkar | 9409ae5 | 2011-04-22 12:09:36 -0500 | [diff] [blame] | 1227 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1228 | cifs_dbg(FYI, "%s: Error %d parsing Owner SID\n", __func__, rc); |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 1229 | return rc; |
Shirish Pargaonkar | 9409ae5 | 2011-04-22 12:09:36 -0500 | [diff] [blame] | 1230 | } |
| 1231 | rc = sid_to_id(cifs_sb, owner_sid_ptr, fattr, SIDOWNER); |
| 1232 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1233 | cifs_dbg(FYI, "%s: Error %d mapping Owner SID to uid\n", |
| 1234 | __func__, rc); |
Shirish Pargaonkar | 9409ae5 | 2011-04-22 12:09:36 -0500 | [diff] [blame] | 1235 | return rc; |
| 1236 | } |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 1237 | |
| 1238 | rc = parse_sid(group_sid_ptr, end_of_acl); |
Shirish Pargaonkar | 9409ae5 | 2011-04-22 12:09:36 -0500 | [diff] [blame] | 1239 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1240 | cifs_dbg(FYI, "%s: Error %d mapping Owner SID to gid\n", |
| 1241 | __func__, rc); |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 1242 | return rc; |
Shirish Pargaonkar | 9409ae5 | 2011-04-22 12:09:36 -0500 | [diff] [blame] | 1243 | } |
| 1244 | rc = sid_to_id(cifs_sb, group_sid_ptr, fattr, SIDGROUP); |
| 1245 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1246 | cifs_dbg(FYI, "%s: Error %d mapping Group SID to gid\n", |
| 1247 | __func__, rc); |
Shirish Pargaonkar | 9409ae5 | 2011-04-22 12:09:36 -0500 | [diff] [blame] | 1248 | return rc; |
| 1249 | } |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 1250 | |
Steve French | 7505e05 | 2007-11-01 18:03:01 +0000 | [diff] [blame] | 1251 | if (dacloffset) |
| 1252 | parse_dacl(dacl_ptr, end_of_acl, owner_sid_ptr, |
Steve French | e2f8fbf | 2019-07-19 06:30:07 +0000 | [diff] [blame] | 1253 | group_sid_ptr, fattr, get_mode_from_special_sid); |
Steve French | 7505e05 | 2007-11-01 18:03:01 +0000 | [diff] [blame] | 1254 | else |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1255 | cifs_dbg(FYI, "no ACL\n"); /* BB grant all or default perms? */ |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 1256 | |
Shirish Pargaonkar | 9409ae5 | 2011-04-22 12:09:36 -0500 | [diff] [blame] | 1257 | return rc; |
Steve French | bcb0203 | 2007-09-25 16:17:24 +0000 | [diff] [blame] | 1258 | } |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 1259 | |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 1260 | /* Convert permission bits from mode to equivalent CIFS ACL */ |
| 1261 | static int build_sec_desc(struct cifs_ntsd *pntsd, struct cifs_ntsd *pnntsd, |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 1262 | __u32 secdesclen, __u32 *pnsecdesclen, __u64 *pnmode, kuid_t uid, kgid_t gid, |
Steve French | a660339 | 2020-06-12 10:36:37 -0500 | [diff] [blame] | 1263 | bool mode_from_sid, bool id_from_sid, int *aclflag) |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 1264 | { |
| 1265 | int rc = 0; |
| 1266 | __u32 dacloffset; |
| 1267 | __u32 ndacloffset; |
| 1268 | __u32 sidsoffset; |
| 1269 | struct cifs_sid *owner_sid_ptr, *group_sid_ptr; |
Shyam Prasad N | bc3e9dd | 2021-02-18 13:03:23 +0000 | [diff] [blame] | 1270 | struct cifs_sid *nowner_sid_ptr = NULL, *ngroup_sid_ptr = NULL; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 1271 | struct cifs_acl *dacl_ptr = NULL; /* no need for SACL ptr */ |
| 1272 | struct cifs_acl *ndacl_ptr = NULL; /* no need for SACL ptr */ |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 1273 | char *end_of_acl = ((char *)pntsd) + secdesclen; |
Shyam Prasad N | bc3e9dd | 2021-02-18 13:03:23 +0000 | [diff] [blame] | 1274 | u16 size = 0; |
| 1275 | |
| 1276 | dacloffset = le32_to_cpu(pntsd->dacloffset); |
| 1277 | if (dacloffset) { |
| 1278 | dacl_ptr = (struct cifs_acl *)((char *)pntsd + dacloffset); |
| 1279 | if (end_of_acl < (char *)dacl_ptr + le16_to_cpu(dacl_ptr->size)) { |
Shyam Prasad N | f1ebe48 | 2021-02-24 15:04:02 +0000 | [diff] [blame] | 1280 | cifs_dbg(VFS, "Server returned illegal ACL size\n"); |
| 1281 | return -EINVAL; |
Shyam Prasad N | bc3e9dd | 2021-02-18 13:03:23 +0000 | [diff] [blame] | 1282 | } |
| 1283 | } |
| 1284 | |
| 1285 | owner_sid_ptr = (struct cifs_sid *)((char *)pntsd + |
| 1286 | le32_to_cpu(pntsd->osidoffset)); |
| 1287 | group_sid_ptr = (struct cifs_sid *)((char *)pntsd + |
| 1288 | le32_to_cpu(pntsd->gsidoffset)); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 1289 | |
Shyam Prasad N | 0f22053 | 2020-08-17 03:23:12 -0700 | [diff] [blame] | 1290 | if (pnmode && *pnmode != NO_CHANGE_64) { /* chmod */ |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 1291 | ndacloffset = sizeof(struct cifs_ntsd); |
| 1292 | ndacl_ptr = (struct cifs_acl *)((char *)pnntsd + ndacloffset); |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 1293 | ndacl_ptr->revision = |
| 1294 | dacloffset ? dacl_ptr->revision : cpu_to_le16(ACL_REVISION); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 1295 | |
Steve French | 23bda5e | 2021-02-22 14:40:43 -0600 | [diff] [blame] | 1296 | ndacl_ptr->size = cpu_to_le16(0); |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 1297 | ndacl_ptr->num_aces = cpu_to_le32(0); |
| 1298 | |
| 1299 | rc = set_chmod_dacl(dacl_ptr, ndacl_ptr, owner_sid_ptr, group_sid_ptr, |
Shyam Prasad N | 0f22053 | 2020-08-17 03:23:12 -0700 | [diff] [blame] | 1300 | pnmode, mode_from_sid); |
Shyam Prasad N | bc3e9dd | 2021-02-18 13:03:23 +0000 | [diff] [blame] | 1301 | |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 1302 | sidsoffset = ndacloffset + le16_to_cpu(ndacl_ptr->size); |
Shyam Prasad N | bc3e9dd | 2021-02-18 13:03:23 +0000 | [diff] [blame] | 1303 | /* copy the non-dacl portion of secdesc */ |
| 1304 | *pnsecdesclen = copy_sec_desc(pntsd, pnntsd, sidsoffset, |
| 1305 | NULL, NULL); |
| 1306 | |
| 1307 | *aclflag |= CIFS_ACL_DACL; |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 1308 | } else { |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 1309 | ndacloffset = sizeof(struct cifs_ntsd); |
| 1310 | ndacl_ptr = (struct cifs_acl *)((char *)pnntsd + ndacloffset); |
| 1311 | ndacl_ptr->revision = |
| 1312 | dacloffset ? dacl_ptr->revision : cpu_to_le16(ACL_REVISION); |
| 1313 | ndacl_ptr->num_aces = dacl_ptr->num_aces; |
| 1314 | |
Eric W. Biederman | 8abf277 | 2013-02-06 00:33:17 -0800 | [diff] [blame] | 1315 | if (uid_valid(uid)) { /* chown */ |
| 1316 | uid_t id; |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 1317 | nowner_sid_ptr = kmalloc(sizeof(struct cifs_sid), |
| 1318 | GFP_KERNEL); |
Shyam Prasad N | bc3e9dd | 2021-02-18 13:03:23 +0000 | [diff] [blame] | 1319 | if (!nowner_sid_ptr) { |
| 1320 | rc = -ENOMEM; |
| 1321 | goto chown_chgrp_exit; |
| 1322 | } |
Eric W. Biederman | 8abf277 | 2013-02-06 00:33:17 -0800 | [diff] [blame] | 1323 | id = from_kuid(&init_user_ns, uid); |
Steve French | a660339 | 2020-06-12 10:36:37 -0500 | [diff] [blame] | 1324 | if (id_from_sid) { |
| 1325 | struct owner_sid *osid = (struct owner_sid *)nowner_sid_ptr; |
| 1326 | /* Populate the user ownership fields S-1-5-88-1 */ |
| 1327 | osid->Revision = 1; |
| 1328 | osid->NumAuth = 3; |
| 1329 | osid->Authority[5] = 5; |
| 1330 | osid->SubAuthorities[0] = cpu_to_le32(88); |
| 1331 | osid->SubAuthorities[1] = cpu_to_le32(1); |
| 1332 | osid->SubAuthorities[2] = cpu_to_le32(id); |
Shyam Prasad N | bc3e9dd | 2021-02-18 13:03:23 +0000 | [diff] [blame] | 1333 | |
Steve French | a660339 | 2020-06-12 10:36:37 -0500 | [diff] [blame] | 1334 | } else { /* lookup sid with upcall */ |
| 1335 | rc = id_to_sid(id, SIDOWNER, nowner_sid_ptr); |
| 1336 | if (rc) { |
| 1337 | cifs_dbg(FYI, "%s: Mapping error %d for owner id %d\n", |
| 1338 | __func__, rc, id); |
Shyam Prasad N | bc3e9dd | 2021-02-18 13:03:23 +0000 | [diff] [blame] | 1339 | goto chown_chgrp_exit; |
Steve French | a660339 | 2020-06-12 10:36:37 -0500 | [diff] [blame] | 1340 | } |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 1341 | } |
Shyam Prasad N | bc3e9dd | 2021-02-18 13:03:23 +0000 | [diff] [blame] | 1342 | *aclflag |= CIFS_ACL_OWNER; |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 1343 | } |
Eric W. Biederman | 8abf277 | 2013-02-06 00:33:17 -0800 | [diff] [blame] | 1344 | if (gid_valid(gid)) { /* chgrp */ |
| 1345 | gid_t id; |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 1346 | ngroup_sid_ptr = kmalloc(sizeof(struct cifs_sid), |
| 1347 | GFP_KERNEL); |
Shyam Prasad N | bc3e9dd | 2021-02-18 13:03:23 +0000 | [diff] [blame] | 1348 | if (!ngroup_sid_ptr) { |
| 1349 | rc = -ENOMEM; |
| 1350 | goto chown_chgrp_exit; |
| 1351 | } |
Eric W. Biederman | 8abf277 | 2013-02-06 00:33:17 -0800 | [diff] [blame] | 1352 | id = from_kgid(&init_user_ns, gid); |
Steve French | a660339 | 2020-06-12 10:36:37 -0500 | [diff] [blame] | 1353 | if (id_from_sid) { |
| 1354 | struct owner_sid *gsid = (struct owner_sid *)ngroup_sid_ptr; |
| 1355 | /* Populate the group ownership fields S-1-5-88-2 */ |
| 1356 | gsid->Revision = 1; |
| 1357 | gsid->NumAuth = 3; |
| 1358 | gsid->Authority[5] = 5; |
| 1359 | gsid->SubAuthorities[0] = cpu_to_le32(88); |
| 1360 | gsid->SubAuthorities[1] = cpu_to_le32(2); |
| 1361 | gsid->SubAuthorities[2] = cpu_to_le32(id); |
Shyam Prasad N | bc3e9dd | 2021-02-18 13:03:23 +0000 | [diff] [blame] | 1362 | |
Steve French | a660339 | 2020-06-12 10:36:37 -0500 | [diff] [blame] | 1363 | } else { /* lookup sid with upcall */ |
| 1364 | rc = id_to_sid(id, SIDGROUP, ngroup_sid_ptr); |
| 1365 | if (rc) { |
| 1366 | cifs_dbg(FYI, "%s: Mapping error %d for group id %d\n", |
| 1367 | __func__, rc, id); |
Shyam Prasad N | bc3e9dd | 2021-02-18 13:03:23 +0000 | [diff] [blame] | 1368 | goto chown_chgrp_exit; |
Steve French | a660339 | 2020-06-12 10:36:37 -0500 | [diff] [blame] | 1369 | } |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 1370 | } |
Shyam Prasad N | bc3e9dd | 2021-02-18 13:03:23 +0000 | [diff] [blame] | 1371 | *aclflag |= CIFS_ACL_GROUP; |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 1372 | } |
Shyam Prasad N | bc3e9dd | 2021-02-18 13:03:23 +0000 | [diff] [blame] | 1373 | |
| 1374 | if (dacloffset) { |
| 1375 | /* Replace ACEs for old owner with new one */ |
| 1376 | size = replace_sids_and_copy_aces(dacl_ptr, ndacl_ptr, |
| 1377 | owner_sid_ptr, group_sid_ptr, |
| 1378 | nowner_sid_ptr, ngroup_sid_ptr); |
| 1379 | ndacl_ptr->size = cpu_to_le16(size); |
| 1380 | } |
| 1381 | |
| 1382 | sidsoffset = ndacloffset + le16_to_cpu(ndacl_ptr->size); |
| 1383 | /* copy the non-dacl portion of secdesc */ |
| 1384 | *pnsecdesclen = copy_sec_desc(pntsd, pnntsd, sidsoffset, |
| 1385 | nowner_sid_ptr, ngroup_sid_ptr); |
| 1386 | |
| 1387 | chown_chgrp_exit: |
| 1388 | /* errors could jump here. So make sure we return soon after this */ |
| 1389 | kfree(nowner_sid_ptr); |
| 1390 | kfree(ngroup_sid_ptr); |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 1391 | } |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 1392 | |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 1393 | return rc; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 1394 | } |
| 1395 | |
Steve French | 42eacf9 | 2014-02-10 14:08:16 -0600 | [diff] [blame] | 1396 | struct cifs_ntsd *get_cifs_acl_by_fid(struct cifs_sb_info *cifs_sb, |
Boris Protopopov | 3970acf | 2020-12-18 11:30:12 -0600 | [diff] [blame] | 1397 | const struct cifs_fid *cifsfid, u32 *pacllen, |
| 1398 | u32 __maybe_unused unused) |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 1399 | { |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 1400 | struct cifs_ntsd *pntsd = NULL; |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1401 | unsigned int xid; |
| 1402 | int rc; |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 1403 | struct tcon_link *tlink = cifs_sb_tlink(cifs_sb); |
| 1404 | |
| 1405 | if (IS_ERR(tlink)) |
Shirish Pargaonkar | 987b21d | 2010-11-10 07:50:35 -0600 | [diff] [blame] | 1406 | return ERR_CAST(tlink); |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 1407 | |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1408 | xid = get_xid(); |
Steve French | 42eacf9 | 2014-02-10 14:08:16 -0600 | [diff] [blame] | 1409 | rc = CIFSSMBGetCIFSACL(xid, tlink_tcon(tlink), cifsfid->netfid, &pntsd, |
| 1410 | pacllen); |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1411 | free_xid(xid); |
Steve French | 8b1327f | 2008-03-14 22:37:16 +0000 | [diff] [blame] | 1412 | |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 1413 | cifs_put_tlink(tlink); |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 1414 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1415 | cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen); |
Shirish Pargaonkar | 987b21d | 2010-11-10 07:50:35 -0600 | [diff] [blame] | 1416 | if (rc) |
| 1417 | return ERR_PTR(rc); |
Christoph Hellwig | 1bf4072 | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 1418 | return pntsd; |
| 1419 | } |
| 1420 | |
| 1421 | static struct cifs_ntsd *get_cifs_acl_by_path(struct cifs_sb_info *cifs_sb, |
| 1422 | const char *path, u32 *pacllen) |
| 1423 | { |
| 1424 | struct cifs_ntsd *pntsd = NULL; |
| 1425 | int oplock = 0; |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1426 | unsigned int xid; |
Amir Goldstein | 0f06093 | 2020-02-03 21:46:43 +0200 | [diff] [blame] | 1427 | int rc; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1428 | struct cifs_tcon *tcon; |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 1429 | struct tcon_link *tlink = cifs_sb_tlink(cifs_sb); |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 1430 | struct cifs_fid fid; |
| 1431 | struct cifs_open_parms oparms; |
Christoph Hellwig | 1bf4072 | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 1432 | |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 1433 | if (IS_ERR(tlink)) |
Shirish Pargaonkar | 987b21d | 2010-11-10 07:50:35 -0600 | [diff] [blame] | 1434 | return ERR_CAST(tlink); |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 1435 | |
| 1436 | tcon = tlink_tcon(tlink); |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1437 | xid = get_xid(); |
Christoph Hellwig | 1bf4072 | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 1438 | |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 1439 | oparms.tcon = tcon; |
| 1440 | oparms.cifs_sb = cifs_sb; |
| 1441 | oparms.desired_access = READ_CONTROL; |
Amir Goldstein | 0f06093 | 2020-02-03 21:46:43 +0200 | [diff] [blame] | 1442 | oparms.create_options = cifs_create_options(cifs_sb, 0); |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 1443 | oparms.disposition = FILE_OPEN; |
| 1444 | oparms.path = path; |
| 1445 | oparms.fid = &fid; |
| 1446 | oparms.reconnect = false; |
| 1447 | |
| 1448 | rc = CIFS_open(xid, &oparms, &oplock, NULL); |
Shirish Pargaonkar | 987b21d | 2010-11-10 07:50:35 -0600 | [diff] [blame] | 1449 | if (!rc) { |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 1450 | rc = CIFSSMBGetCIFSACL(xid, tcon, fid.netfid, &pntsd, pacllen); |
| 1451 | CIFSSMBClose(xid, tcon, fid.netfid); |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 1452 | } |
| 1453 | |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 1454 | cifs_put_tlink(tlink); |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1455 | free_xid(xid); |
Shirish Pargaonkar | 987b21d | 2010-11-10 07:50:35 -0600 | [diff] [blame] | 1456 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1457 | cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen); |
Shirish Pargaonkar | 987b21d | 2010-11-10 07:50:35 -0600 | [diff] [blame] | 1458 | if (rc) |
| 1459 | return ERR_PTR(rc); |
Steve French | 7505e05 | 2007-11-01 18:03:01 +0000 | [diff] [blame] | 1460 | return pntsd; |
| 1461 | } |
| 1462 | |
Christoph Hellwig | 1bf4072 | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 1463 | /* Retrieve an ACL from the server */ |
Shirish Pargaonkar | fbeba8b | 2010-11-27 11:37:54 -0600 | [diff] [blame] | 1464 | struct cifs_ntsd *get_cifs_acl(struct cifs_sb_info *cifs_sb, |
Christoph Hellwig | 1bf4072 | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 1465 | struct inode *inode, const char *path, |
Boris Protopopov | 3970acf | 2020-12-18 11:30:12 -0600 | [diff] [blame] | 1466 | u32 *pacllen, u32 info) |
Christoph Hellwig | 1bf4072 | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 1467 | { |
| 1468 | struct cifs_ntsd *pntsd = NULL; |
| 1469 | struct cifsFileInfo *open_file = NULL; |
| 1470 | |
| 1471 | if (inode) |
Jeff Layton | 6508d90 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 1472 | open_file = find_readable_file(CIFS_I(inode), true); |
Christoph Hellwig | 1bf4072 | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 1473 | if (!open_file) |
| 1474 | return get_cifs_acl_by_path(cifs_sb, path, pacllen); |
| 1475 | |
Boris Protopopov | 3970acf | 2020-12-18 11:30:12 -0600 | [diff] [blame] | 1476 | pntsd = get_cifs_acl_by_fid(cifs_sb, &open_file->fid, pacllen, info); |
Dave Kleikamp | 6ab409b | 2009-08-31 11:07:12 -0400 | [diff] [blame] | 1477 | cifsFileInfo_put(open_file); |
Christoph Hellwig | 1bf4072 | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 1478 | return pntsd; |
| 1479 | } |
| 1480 | |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 1481 | /* Set an ACL on the server */ |
| 1482 | int set_cifs_acl(struct cifs_ntsd *pnntsd, __u32 acllen, |
| 1483 | struct inode *inode, const char *path, int aclflag) |
Christoph Hellwig | b96d31a | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 1484 | { |
| 1485 | int oplock = 0; |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1486 | unsigned int xid; |
Amir Goldstein | 0f06093 | 2020-02-03 21:46:43 +0200 | [diff] [blame] | 1487 | int rc, access_flags; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 1488 | struct cifs_tcon *tcon; |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 1489 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 1490 | struct tcon_link *tlink = cifs_sb_tlink(cifs_sb); |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 1491 | struct cifs_fid fid; |
| 1492 | struct cifs_open_parms oparms; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 1493 | |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 1494 | if (IS_ERR(tlink)) |
| 1495 | return PTR_ERR(tlink); |
| 1496 | |
| 1497 | tcon = tlink_tcon(tlink); |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1498 | xid = get_xid(); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 1499 | |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 1500 | if (aclflag == CIFS_ACL_OWNER || aclflag == CIFS_ACL_GROUP) |
| 1501 | access_flags = WRITE_OWNER; |
| 1502 | else |
| 1503 | access_flags = WRITE_DAC; |
| 1504 | |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 1505 | oparms.tcon = tcon; |
| 1506 | oparms.cifs_sb = cifs_sb; |
| 1507 | oparms.desired_access = access_flags; |
Amir Goldstein | 0f06093 | 2020-02-03 21:46:43 +0200 | [diff] [blame] | 1508 | oparms.create_options = cifs_create_options(cifs_sb, 0); |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 1509 | oparms.disposition = FILE_OPEN; |
| 1510 | oparms.path = path; |
| 1511 | oparms.fid = &fid; |
| 1512 | oparms.reconnect = false; |
| 1513 | |
| 1514 | rc = CIFS_open(xid, &oparms, &oplock, NULL); |
Christoph Hellwig | b96d31a | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 1515 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1516 | cifs_dbg(VFS, "Unable to open file to set ACL\n"); |
Christoph Hellwig | b96d31a | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 1517 | goto out; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 1518 | } |
| 1519 | |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 1520 | rc = CIFSSMBSetCIFSACL(xid, tcon, fid.netfid, pnntsd, acllen, aclflag); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1521 | cifs_dbg(NOISY, "SetCIFSACL rc = %d\n", rc); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 1522 | |
Pavel Shilovsky | d81b8a4 | 2014-01-16 15:53:36 +0400 | [diff] [blame] | 1523 | CIFSSMBClose(xid, tcon, fid.netfid); |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 1524 | out: |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 1525 | free_xid(xid); |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 1526 | cifs_put_tlink(tlink); |
Christoph Hellwig | b96d31a | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 1527 | return rc; |
| 1528 | } |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 1529 | |
Achilles Gaikwad | 36c7ce4 | 2018-01-28 13:39:48 +0530 | [diff] [blame] | 1530 | /* Translate the CIFS ACL (similar to NTFS ACL) for a file into mode bits */ |
Shirish Pargaonkar | 987b21d | 2010-11-10 07:50:35 -0600 | [diff] [blame] | 1531 | int |
Jeff Layton | 0b8f18e | 2009-07-09 01:46:37 -0400 | [diff] [blame] | 1532 | cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb, struct cifs_fattr *fattr, |
Steve French | e2f8fbf | 2019-07-19 06:30:07 +0000 | [diff] [blame] | 1533 | struct inode *inode, bool mode_from_special_sid, |
| 1534 | const char *path, const struct cifs_fid *pfid) |
Steve French | 7505e05 | 2007-11-01 18:03:01 +0000 | [diff] [blame] | 1535 | { |
| 1536 | struct cifs_ntsd *pntsd = NULL; |
| 1537 | u32 acllen = 0; |
| 1538 | int rc = 0; |
Steve French | 42eacf9 | 2014-02-10 14:08:16 -0600 | [diff] [blame] | 1539 | struct tcon_link *tlink = cifs_sb_tlink(cifs_sb); |
Joe Perches via samba-technical | ecdcf62 | 2017-05-07 01:31:47 -0700 | [diff] [blame] | 1540 | struct smb_version_operations *ops; |
Boris Protopopov | 3970acf | 2020-12-18 11:30:12 -0600 | [diff] [blame] | 1541 | const u32 info = 0; |
Steve French | 7505e05 | 2007-11-01 18:03:01 +0000 | [diff] [blame] | 1542 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1543 | cifs_dbg(NOISY, "converting ACL to mode for %s\n", path); |
Christoph Hellwig | 1bf4072 | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 1544 | |
Steve French | 42eacf9 | 2014-02-10 14:08:16 -0600 | [diff] [blame] | 1545 | if (IS_ERR(tlink)) |
| 1546 | return PTR_ERR(tlink); |
Steve French | 7505e05 | 2007-11-01 18:03:01 +0000 | [diff] [blame] | 1547 | |
Joe Perches via samba-technical | ecdcf62 | 2017-05-07 01:31:47 -0700 | [diff] [blame] | 1548 | ops = tlink_tcon(tlink)->ses->server->ops; |
| 1549 | |
| 1550 | if (pfid && (ops->get_acl_by_fid)) |
Boris Protopopov | 3970acf | 2020-12-18 11:30:12 -0600 | [diff] [blame] | 1551 | pntsd = ops->get_acl_by_fid(cifs_sb, pfid, &acllen, info); |
Joe Perches via samba-technical | ecdcf62 | 2017-05-07 01:31:47 -0700 | [diff] [blame] | 1552 | else if (ops->get_acl) |
Boris Protopopov | 3970acf | 2020-12-18 11:30:12 -0600 | [diff] [blame] | 1553 | pntsd = ops->get_acl(cifs_sb, inode, path, &acllen, info); |
Steve French | 42eacf9 | 2014-02-10 14:08:16 -0600 | [diff] [blame] | 1554 | else { |
| 1555 | cifs_put_tlink(tlink); |
| 1556 | return -EOPNOTSUPP; |
| 1557 | } |
Steve French | 7505e05 | 2007-11-01 18:03:01 +0000 | [diff] [blame] | 1558 | /* if we can retrieve the ACL, now parse Access Control Entries, ACEs */ |
Shirish Pargaonkar | 987b21d | 2010-11-10 07:50:35 -0600 | [diff] [blame] | 1559 | if (IS_ERR(pntsd)) { |
| 1560 | rc = PTR_ERR(pntsd); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1561 | cifs_dbg(VFS, "%s: error %d getting sec desc\n", __func__, rc); |
Steve French | e2f8fbf | 2019-07-19 06:30:07 +0000 | [diff] [blame] | 1562 | } else if (mode_from_special_sid) { |
| 1563 | rc = parse_sec_desc(cifs_sb, pntsd, acllen, fattr, true); |
Namjae Jeon | 9812857 | 2020-11-09 17:35:33 +0900 | [diff] [blame] | 1564 | kfree(pntsd); |
Shirish Pargaonkar | 987b21d | 2010-11-10 07:50:35 -0600 | [diff] [blame] | 1565 | } else { |
Steve French | e2f8fbf | 2019-07-19 06:30:07 +0000 | [diff] [blame] | 1566 | /* get approximated mode from ACL */ |
| 1567 | rc = parse_sec_desc(cifs_sb, pntsd, acllen, fattr, false); |
Shirish Pargaonkar | 987b21d | 2010-11-10 07:50:35 -0600 | [diff] [blame] | 1568 | kfree(pntsd); |
| 1569 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1570 | cifs_dbg(VFS, "parse sec desc failed rc = %d\n", rc); |
Shirish Pargaonkar | 987b21d | 2010-11-10 07:50:35 -0600 | [diff] [blame] | 1571 | } |
Steve French | 7505e05 | 2007-11-01 18:03:01 +0000 | [diff] [blame] | 1572 | |
Steve French | 42eacf9 | 2014-02-10 14:08:16 -0600 | [diff] [blame] | 1573 | cifs_put_tlink(tlink); |
| 1574 | |
Shirish Pargaonkar | 987b21d | 2010-11-10 07:50:35 -0600 | [diff] [blame] | 1575 | return rc; |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 1576 | } |
Steve French | 953f868 | 2007-10-31 04:54:42 +0000 | [diff] [blame] | 1577 | |
Steve French | 7505e05 | 2007-11-01 18:03:01 +0000 | [diff] [blame] | 1578 | /* Convert mode bits to an ACL so we can update the ACL on the server */ |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 1579 | int |
Shyam Prasad N | 0f22053 | 2020-08-17 03:23:12 -0700 | [diff] [blame] | 1580 | id_mode_to_cifs_acl(struct inode *inode, const char *path, __u64 *pnmode, |
Eric W. Biederman | 8abf277 | 2013-02-06 00:33:17 -0800 | [diff] [blame] | 1581 | kuid_t uid, kgid_t gid) |
Steve French | 953f868 | 2007-10-31 04:54:42 +0000 | [diff] [blame] | 1582 | { |
| 1583 | int rc = 0; |
Shirish Pargaonkar | a5ff376 | 2011-10-13 10:26:03 -0500 | [diff] [blame] | 1584 | int aclflag = CIFS_ACL_DACL; /* default flag to set */ |
Steve French | cce246e | 2008-04-09 20:55:31 +0000 | [diff] [blame] | 1585 | __u32 secdesclen = 0; |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 1586 | __u32 nsecdesclen = 0; |
| 1587 | __u32 dacloffset = 0; |
| 1588 | struct cifs_acl *dacl_ptr = NULL; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 1589 | struct cifs_ntsd *pntsd = NULL; /* acl obtained from server */ |
| 1590 | struct cifs_ntsd *pnntsd = NULL; /* modified acl to be sent to server */ |
Steve French | 83e3bc2 | 2014-02-02 23:31:47 -0600 | [diff] [blame] | 1591 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
| 1592 | struct tcon_link *tlink = cifs_sb_tlink(cifs_sb); |
Joe Perches via samba-technical | ecdcf62 | 2017-05-07 01:31:47 -0700 | [diff] [blame] | 1593 | struct smb_version_operations *ops; |
Steve French | a660339 | 2020-06-12 10:36:37 -0500 | [diff] [blame] | 1594 | bool mode_from_sid, id_from_sid; |
Boris Protopopov | 3970acf | 2020-12-18 11:30:12 -0600 | [diff] [blame] | 1595 | const u32 info = 0; |
Steve French | 83e3bc2 | 2014-02-02 23:31:47 -0600 | [diff] [blame] | 1596 | |
| 1597 | if (IS_ERR(tlink)) |
| 1598 | return PTR_ERR(tlink); |
Joe Perches via samba-technical | ecdcf62 | 2017-05-07 01:31:47 -0700 | [diff] [blame] | 1599 | |
| 1600 | ops = tlink_tcon(tlink)->ses->server->ops; |
Steve French | 953f868 | 2007-10-31 04:54:42 +0000 | [diff] [blame] | 1601 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1602 | cifs_dbg(NOISY, "set ACL from mode for %s\n", path); |
Steve French | 953f868 | 2007-10-31 04:54:42 +0000 | [diff] [blame] | 1603 | |
| 1604 | /* Get the security descriptor */ |
Steve French | 83e3bc2 | 2014-02-02 23:31:47 -0600 | [diff] [blame] | 1605 | |
Joe Perches via samba-technical | ecdcf62 | 2017-05-07 01:31:47 -0700 | [diff] [blame] | 1606 | if (ops->get_acl == NULL) { |
Steve French | 83e3bc2 | 2014-02-02 23:31:47 -0600 | [diff] [blame] | 1607 | cifs_put_tlink(tlink); |
| 1608 | return -EOPNOTSUPP; |
| 1609 | } |
| 1610 | |
Boris Protopopov | 3970acf | 2020-12-18 11:30:12 -0600 | [diff] [blame] | 1611 | pntsd = ops->get_acl(cifs_sb, inode, path, &secdesclen, info); |
Shirish Pargaonkar | 987b21d | 2010-11-10 07:50:35 -0600 | [diff] [blame] | 1612 | if (IS_ERR(pntsd)) { |
| 1613 | rc = PTR_ERR(pntsd); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1614 | cifs_dbg(VFS, "%s: error %d getting sec desc\n", __func__, rc); |
Steve French | 83e3bc2 | 2014-02-02 23:31:47 -0600 | [diff] [blame] | 1615 | cifs_put_tlink(tlink); |
| 1616 | return rc; |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 1617 | } |
| 1618 | |
Steve French | 2244217 | 2019-07-19 08:15:55 +0000 | [diff] [blame] | 1619 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MODE_FROM_SID) |
| 1620 | mode_from_sid = true; |
| 1621 | else |
| 1622 | mode_from_sid = false; |
| 1623 | |
Steve French | a660339 | 2020-06-12 10:36:37 -0500 | [diff] [blame] | 1624 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UID_FROM_ACL) |
| 1625 | id_from_sid = true; |
| 1626 | else |
| 1627 | id_from_sid = false; |
| 1628 | |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 1629 | /* Potentially, five new ACEs can be added to the ACL for U,G,O mapping */ |
| 1630 | nsecdesclen = secdesclen; |
| 1631 | if (pnmode && *pnmode != NO_CHANGE_64) { /* chmod */ |
| 1632 | if (mode_from_sid) |
| 1633 | nsecdesclen += sizeof(struct cifs_ace); |
| 1634 | else /* cifsacl */ |
| 1635 | nsecdesclen += 5 * sizeof(struct cifs_ace); |
Shyam Prasad N | bc3e9dd | 2021-02-18 13:03:23 +0000 | [diff] [blame] | 1636 | } else { /* chown */ |
| 1637 | /* When ownership changes, changes new owner sid length could be different */ |
| 1638 | nsecdesclen = sizeof(struct cifs_ntsd) + (sizeof(struct cifs_sid) * 2); |
| 1639 | dacloffset = le32_to_cpu(pntsd->dacloffset); |
| 1640 | if (dacloffset) { |
| 1641 | dacl_ptr = (struct cifs_acl *)((char *)pntsd + dacloffset); |
| 1642 | if (mode_from_sid) |
| 1643 | nsecdesclen += |
Steve French | 23bda5e | 2021-02-22 14:40:43 -0600 | [diff] [blame] | 1644 | le32_to_cpu(dacl_ptr->num_aces) * sizeof(struct cifs_ace); |
Shyam Prasad N | bc3e9dd | 2021-02-18 13:03:23 +0000 | [diff] [blame] | 1645 | else /* cifsacl */ |
| 1646 | nsecdesclen += le16_to_cpu(dacl_ptr->size); |
| 1647 | } |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 1648 | } |
| 1649 | |
| 1650 | /* |
| 1651 | * Add three ACEs for owner, group, everyone getting rid of other ACEs |
| 1652 | * as chmod disables ACEs and set the security descriptor. Allocate |
| 1653 | * memory for the smb header, set security descriptor request security |
jack1.li_cp | c45adff | 2021-04-09 22:00:37 -0500 | [diff] [blame^] | 1654 | * descriptor parameters, and security descriptor itself |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 1655 | */ |
| 1656 | nsecdesclen = max_t(u32, nsecdesclen, DEFAULT_SEC_DESC_LEN); |
| 1657 | pnntsd = kmalloc(nsecdesclen, GFP_KERNEL); |
| 1658 | if (!pnntsd) { |
| 1659 | kfree(pntsd); |
| 1660 | cifs_put_tlink(tlink); |
| 1661 | return -ENOMEM; |
| 1662 | } |
| 1663 | |
| 1664 | rc = build_sec_desc(pntsd, pnntsd, secdesclen, &nsecdesclen, pnmode, uid, gid, |
Steve French | a660339 | 2020-06-12 10:36:37 -0500 | [diff] [blame] | 1665 | mode_from_sid, id_from_sid, &aclflag); |
Jeff Layton | c78cd83 | 2012-11-25 08:00:35 -0500 | [diff] [blame] | 1666 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1667 | cifs_dbg(NOISY, "build_sec_desc rc: %d\n", rc); |
Jeff Layton | c78cd83 | 2012-11-25 08:00:35 -0500 | [diff] [blame] | 1668 | |
Joe Perches via samba-technical | ecdcf62 | 2017-05-07 01:31:47 -0700 | [diff] [blame] | 1669 | if (ops->set_acl == NULL) |
Steve French | 83e3bc2 | 2014-02-02 23:31:47 -0600 | [diff] [blame] | 1670 | rc = -EOPNOTSUPP; |
| 1671 | |
Jeff Layton | c78cd83 | 2012-11-25 08:00:35 -0500 | [diff] [blame] | 1672 | if (!rc) { |
| 1673 | /* Set the security descriptor */ |
Shyam Prasad N | f506550 | 2021-02-12 04:38:43 -0800 | [diff] [blame] | 1674 | rc = ops->set_acl(pnntsd, nsecdesclen, inode, path, aclflag); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1675 | cifs_dbg(NOISY, "set_cifs_acl rc: %d\n", rc); |
Jeff Layton | c78cd83 | 2012-11-25 08:00:35 -0500 | [diff] [blame] | 1676 | } |
Steve French | 83e3bc2 | 2014-02-02 23:31:47 -0600 | [diff] [blame] | 1677 | cifs_put_tlink(tlink); |
Jeff Layton | c78cd83 | 2012-11-25 08:00:35 -0500 | [diff] [blame] | 1678 | |
| 1679 | kfree(pnntsd); |
| 1680 | kfree(pntsd); |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 1681 | return rc; |
Steve French | 953f868 | 2007-10-31 04:54:42 +0000 | [diff] [blame] | 1682 | } |