Linux Audio

Check our new training course

Real-Time Linux with PREEMPT_RT training

Feb 18-20, 2025
Register
Loading...
v4.17
  1/* AFS security handling
  2 *
  3 * Copyright (C) 2007, 2017 Red Hat, Inc. All Rights Reserved.
  4 * Written by David Howells (dhowells@redhat.com)
  5 *
  6 * This program is free software; you can redistribute it and/or
  7 * modify it under the terms of the GNU General Public License
  8 * as published by the Free Software Foundation; either version
  9 * 2 of the License, or (at your option) any later version.
 10 */
 11
 12#include <linux/init.h>
 13#include <linux/slab.h>
 14#include <linux/fs.h>
 15#include <linux/ctype.h>
 16#include <linux/sched.h>
 17#include <linux/hashtable.h>
 18#include <keys/rxrpc-type.h>
 19#include "internal.h"
 20
 21static DEFINE_HASHTABLE(afs_permits_cache, 10);
 22static DEFINE_SPINLOCK(afs_permits_lock);
 23
 24/*
 25 * get a key
 26 */
 27struct key *afs_request_key(struct afs_cell *cell)
 28{
 29	struct key *key;
 30
 31	_enter("{%x}", key_serial(cell->anonymous_key));
 32
 33	_debug("key %s", cell->anonymous_key->description);
 34	key = request_key(&key_type_rxrpc, cell->anonymous_key->description,
 35			  NULL);
 36	if (IS_ERR(key)) {
 37		if (PTR_ERR(key) != -ENOKEY) {
 38			_leave(" = %ld", PTR_ERR(key));
 39			return key;
 40		}
 41
 42		/* act as anonymous user */
 43		_leave(" = {%x} [anon]", key_serial(cell->anonymous_key));
 44		return key_get(cell->anonymous_key);
 45	} else {
 46		/* act as authorised user */
 47		_leave(" = {%x} [auth]", key_serial(key));
 48		return key;
 49	}
 50}
 51
 52/*
 53 * Dispose of a list of permits.
 54 */
 55static void afs_permits_rcu(struct rcu_head *rcu)
 56{
 57	struct afs_permits *permits =
 58		container_of(rcu, struct afs_permits, rcu);
 59	int i;
 
 
 60
 61	for (i = 0; i < permits->nr_permits; i++)
 62		key_put(permits->permits[i].key);
 63	kfree(permits);
 64}
 65
 66/*
 67 * Discard a permission cache.
 68 */
 69void afs_put_permits(struct afs_permits *permits)
 70{
 71	if (permits && refcount_dec_and_test(&permits->usage)) {
 72		spin_lock(&afs_permits_lock);
 73		hash_del_rcu(&permits->hash_node);
 74		spin_unlock(&afs_permits_lock);
 75		call_rcu(&permits->rcu, afs_permits_rcu);
 76	}
 77}
 78
 79/*
 80 * Clear a permit cache on callback break.
 81 */
 82void afs_clear_permits(struct afs_vnode *vnode)
 83{
 84	struct afs_permits *permits;
 85
 86	spin_lock(&vnode->lock);
 87	permits = rcu_dereference_protected(vnode->permit_cache,
 88					    lockdep_is_held(&vnode->lock));
 89	RCU_INIT_POINTER(vnode->permit_cache, NULL);
 90	vnode->cb_break++;
 91	spin_unlock(&vnode->lock);
 92
 93	if (permits)
 94		afs_put_permits(permits);
 95}
 96
 97/*
 98 * Hash a list of permits.  Use simple addition to make it easy to add an extra
 99 * one at an as-yet indeterminate position in the list.
 
 
100 */
101static void afs_hash_permits(struct afs_permits *permits)
 
102{
103	unsigned long h = permits->nr_permits;
104	int i;
 
 
105
106	for (i = 0; i < permits->nr_permits; i++) {
107		h += (unsigned long)permits->permits[i].key / sizeof(void *);
108		h += permits->permits[i].access;
 
 
 
 
 
109	}
110
111	permits->h = h;
 
 
112}
113
114/*
115 * Cache the CallerAccess result obtained from doing a fileserver operation
116 * that returned a vnode status for a particular key.  If a callback break
117 * occurs whilst the operation was in progress then we have to ditch the cache
118 * as the ACL *may* have changed.
119 */
120void afs_cache_permit(struct afs_vnode *vnode, struct key *key,
121		      unsigned int cb_break)
122{
123	struct afs_permits *permits, *xpermits, *replacement, *zap, *new = NULL;
124	afs_access_t caller_access = READ_ONCE(vnode->status.caller_access);
125	size_t size = 0;
126	bool changed = false;
127	int i, j;
128
129	_enter("{%x:%u},%x,%x",
130	       vnode->fid.vid, vnode->fid.vnode, key_serial(key), caller_access);
131
132	rcu_read_lock();
133
134	/* Check for the common case first: We got back the same access as last
135	 * time we tried and already have it recorded.
136	 */
137	permits = rcu_dereference(vnode->permit_cache);
138	if (permits) {
139		if (!permits->invalidated) {
140			for (i = 0; i < permits->nr_permits; i++) {
141				if (permits->permits[i].key < key)
142					continue;
143				if (permits->permits[i].key > key)
144					break;
145				if (permits->permits[i].access != caller_access) {
146					changed = true;
147					break;
148				}
149
150				if (cb_break != afs_cb_break_sum(vnode, vnode->cb_interest)) {
151					changed = true;
152					break;
153				}
154
155				/* The cache is still good. */
156				rcu_read_unlock();
157				return;
158			}
159		}
160
161		changed |= permits->invalidated;
162		size = permits->nr_permits;
 
 
163
164		/* If this set of permits is now wrong, clear the permits
165		 * pointer so that no one tries to use the stale information.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166		 */
167		if (changed) {
168			spin_lock(&vnode->lock);
169			if (permits != rcu_access_pointer(vnode->permit_cache))
170				goto someone_else_changed_it_unlock;
171			RCU_INIT_POINTER(vnode->permit_cache, NULL);
172			spin_unlock(&vnode->lock);
173
174			afs_put_permits(permits);
175			permits = NULL;
176			size = 0;
177		}
178	}
179
180	if (cb_break != afs_cb_break_sum(vnode, vnode->cb_interest))
181		goto someone_else_changed_it;
182
183	/* We need a ref on any permits list we want to copy as we'll have to
184	 * drop the lock to do memory allocation.
185	 */
186	if (permits && !refcount_inc_not_zero(&permits->usage))
187		goto someone_else_changed_it;
188
189	rcu_read_unlock();
190
191	/* Speculatively create a new list with the revised permission set.  We
192	 * discard this if we find an extant match already in the hash, but
193	 * it's easier to compare with memcmp this way.
194	 *
195	 * We fill in the key pointers at this time, but we don't get the refs
196	 * yet.
197	 */
198	size++;
199	new = kzalloc(sizeof(struct afs_permits) +
200		      sizeof(struct afs_permit) * size, GFP_NOFS);
201	if (!new)
202		goto out_put;
203
204	refcount_set(&new->usage, 1);
205	new->nr_permits = size;
206	i = j = 0;
207	if (permits) {
208		for (i = 0; i < permits->nr_permits; i++) {
209			if (j == i && permits->permits[i].key > key) {
210				new->permits[j].key = key;
211				new->permits[j].access = caller_access;
212				j++;
213			}
214			new->permits[j].key = permits->permits[i].key;
215			new->permits[j].access = permits->permits[i].access;
216			j++;
217		}
218	}
219
220	if (j == i) {
221		new->permits[j].key = key;
222		new->permits[j].access = caller_access;
223	}
224
225	afs_hash_permits(new);
226
227	/* Now see if the permit list we want is actually already available */
228	spin_lock(&afs_permits_lock);
229
230	hash_for_each_possible(afs_permits_cache, xpermits, hash_node, new->h) {
231		if (xpermits->h != new->h ||
232		    xpermits->invalidated ||
233		    xpermits->nr_permits != new->nr_permits ||
234		    memcmp(xpermits->permits, new->permits,
235			   new->nr_permits * sizeof(struct afs_permit)) != 0)
236			continue;
237
238		if (refcount_inc_not_zero(&xpermits->usage)) {
239			replacement = xpermits;
240			goto found;
241		}
242
243		break;
244	}
245
246	for (i = 0; i < new->nr_permits; i++)
247		key_get(new->permits[i].key);
248	hash_add_rcu(afs_permits_cache, &new->hash_node, new->h);
249	replacement = new;
250	new = NULL;
251
252found:
253	spin_unlock(&afs_permits_lock);
254
255	kfree(new);
256
257	spin_lock(&vnode->lock);
258	zap = rcu_access_pointer(vnode->permit_cache);
259	if (cb_break == afs_cb_break_sum(vnode, vnode->cb_interest) &&
260	    zap == permits)
261		rcu_assign_pointer(vnode->permit_cache, replacement);
262	else
263		zap = replacement;
264	spin_unlock(&vnode->lock);
265	afs_put_permits(zap);
266out_put:
267	afs_put_permits(permits);
268	return;
269
270someone_else_changed_it_unlock:
271	spin_unlock(&vnode->lock);
272someone_else_changed_it:
273	/* Someone else changed the cache under us - don't recheck at this
274	 * time.
275	 */
276	rcu_read_unlock();
277	return;
278}
279
280/*
281 * check with the fileserver to see if the directory or parent directory is
282 * permitted to be accessed with this authorisation, and if so, what access it
283 * is granted
284 */
285int afs_check_permit(struct afs_vnode *vnode, struct key *key,
286		     afs_access_t *_access)
287{
288	struct afs_permits *permits;
289	bool valid = false;
290	int i, ret;
 
 
291
292	_enter("{%x:%u},%x",
293	       vnode->fid.vid, vnode->fid.vnode, key_serial(key));
294
 
 
 
 
 
 
 
 
 
295	/* check the permits to see if we've got one yet */
296	if (key == vnode->volume->cell->anonymous_key) {
297		_debug("anon");
298		*_access = vnode->status.anon_access;
299		valid = true;
300	} else {
 
301		rcu_read_lock();
302		permits = rcu_dereference(vnode->permit_cache);
303		if (permits) {
304			for (i = 0; i < permits->nr_permits; i++) {
305				if (permits->permits[i].key < key)
306					continue;
307				if (permits->permits[i].key > key)
 
 
308					break;
309
310				*_access = permits->permits[i].access;
311				valid = !permits->invalidated;
312				break;
313			}
314		}
315		rcu_read_unlock();
316	}
317
318	if (!valid) {
319		/* Check the status on the file we're actually interested in
320		 * (the post-processing will cache the result).
321		 */
322		_debug("no valid permit");
323
324		ret = afs_fetch_status(vnode, key, false);
 
325		if (ret < 0) {
 
326			*_access = 0;
327			_leave(" = %d", ret);
328			return ret;
329		}
330		*_access = vnode->status.caller_access;
331	}
332
 
333	_leave(" = 0 [access %x]", *_access);
334	return 0;
335}
336
337/*
338 * check the permissions on an AFS file
339 * - AFS ACLs are attached to directories only, and a file is controlled by its
340 *   parent directory's ACL
341 */
342int afs_permission(struct inode *inode, int mask)
343{
344	struct afs_vnode *vnode = AFS_FS_I(inode);
345	afs_access_t uninitialized_var(access);
346	struct key *key;
347	int ret;
348
349	if (mask & MAY_NOT_BLOCK)
350		return -ECHILD;
351
352	_enter("{{%x:%u},%lx},%x,",
353	       vnode->fid.vid, vnode->fid.vnode, vnode->flags, mask);
354
355	key = afs_request_key(vnode->volume->cell);
356	if (IS_ERR(key)) {
357		_leave(" = %ld [key]", PTR_ERR(key));
358		return PTR_ERR(key);
359	}
360
361	ret = afs_validate(vnode, key);
362	if (ret < 0)
363		goto error;
 
 
 
 
 
364
365	/* check the permits to see if we've got one yet */
366	ret = afs_check_permit(vnode, key, &access);
367	if (ret < 0)
368		goto error;
369
370	/* interpret the access mask */
371	_debug("REQ %x ACC %x on %s",
372	       mask, access, S_ISDIR(inode->i_mode) ? "dir" : "file");
373
374	if (S_ISDIR(inode->i_mode)) {
375		if (mask & (MAY_EXEC | MAY_READ | MAY_CHDIR)) {
376			if (!(access & AFS_ACE_LOOKUP))
377				goto permission_denied;
378		}
379		if (mask & MAY_WRITE) {
 
 
380			if (!(access & (AFS_ACE_DELETE | /* rmdir, unlink, rename from */
381					AFS_ACE_INSERT))) /* create, mkdir, symlink, rename to */
 
382				goto permission_denied;
 
 
383		}
384	} else {
385		if (!(access & AFS_ACE_LOOKUP))
386			goto permission_denied;
387		if ((mask & MAY_EXEC) && !(inode->i_mode & S_IXUSR))
388			goto permission_denied;
389		if (mask & (MAY_EXEC | MAY_READ)) {
390			if (!(access & AFS_ACE_READ))
391				goto permission_denied;
392			if (!(inode->i_mode & S_IRUSR))
393				goto permission_denied;
394		} else if (mask & MAY_WRITE) {
395			if (!(access & AFS_ACE_WRITE))
396				goto permission_denied;
397			if (!(inode->i_mode & S_IWUSR))
398				goto permission_denied;
399		}
400	}
401
402	key_put(key);
 
403	_leave(" = %d", ret);
404	return ret;
405
406permission_denied:
407	ret = -EACCES;
408error:
409	key_put(key);
410	_leave(" = %d", ret);
411	return ret;
412}
413
414void __exit afs_clean_up_permit_cache(void)
415{
416	int i;
417
418	for (i = 0; i < HASH_SIZE(afs_permits_cache); i++)
419		WARN_ON_ONCE(!hlist_empty(&afs_permits_cache[i]));
420
421}
v3.1
  1/* AFS security handling
  2 *
  3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
  4 * Written by David Howells (dhowells@redhat.com)
  5 *
  6 * This program is free software; you can redistribute it and/or
  7 * modify it under the terms of the GNU General Public License
  8 * as published by the Free Software Foundation; either version
  9 * 2 of the License, or (at your option) any later version.
 10 */
 11
 12#include <linux/init.h>
 13#include <linux/slab.h>
 14#include <linux/fs.h>
 15#include <linux/ctype.h>
 16#include <linux/sched.h>
 
 17#include <keys/rxrpc-type.h>
 18#include "internal.h"
 19
 
 
 
 20/*
 21 * get a key
 22 */
 23struct key *afs_request_key(struct afs_cell *cell)
 24{
 25	struct key *key;
 26
 27	_enter("{%x}", key_serial(cell->anonymous_key));
 28
 29	_debug("key %s", cell->anonymous_key->description);
 30	key = request_key(&key_type_rxrpc, cell->anonymous_key->description,
 31			  NULL);
 32	if (IS_ERR(key)) {
 33		if (PTR_ERR(key) != -ENOKEY) {
 34			_leave(" = %ld", PTR_ERR(key));
 35			return key;
 36		}
 37
 38		/* act as anonymous user */
 39		_leave(" = {%x} [anon]", key_serial(cell->anonymous_key));
 40		return key_get(cell->anonymous_key);
 41	} else {
 42		/* act as authorised user */
 43		_leave(" = {%x} [auth]", key_serial(key));
 44		return key;
 45	}
 46}
 47
 48/*
 49 * dispose of a permits list
 50 */
 51void afs_zap_permits(struct rcu_head *rcu)
 52{
 53	struct afs_permits *permits =
 54		container_of(rcu, struct afs_permits, rcu);
 55	int loop;
 56
 57	_enter("{%d}", permits->count);
 58
 59	for (loop = permits->count - 1; loop >= 0; loop--)
 60		key_put(permits->permits[loop].key);
 61	kfree(permits);
 62}
 63
 64/*
 65 * dispose of a permits list in which all the key pointers have been copied
 66 */
 67static void afs_dispose_of_permits(struct rcu_head *rcu)
 68{
 69	struct afs_permits *permits =
 70		container_of(rcu, struct afs_permits, rcu);
 
 
 
 
 
 
 
 
 
 
 
 
 71
 72	_enter("{%d}", permits->count);
 
 
 
 
 
 73
 74	kfree(permits);
 
 75}
 76
 77/*
 78 * get the authorising vnode - this is the specified inode itself if it's a
 79 * directory or it's the parent directory if the specified inode is a file or
 80 * symlink
 81 * - the caller must release the ref on the inode
 82 */
 83static struct afs_vnode *afs_get_auth_inode(struct afs_vnode *vnode,
 84					    struct key *key)
 85{
 86	struct afs_vnode *auth_vnode;
 87	struct inode *auth_inode;
 88
 89	_enter("");
 90
 91	if (S_ISDIR(vnode->vfs_inode.i_mode)) {
 92		auth_inode = igrab(&vnode->vfs_inode);
 93		ASSERT(auth_inode != NULL);
 94	} else {
 95		auth_inode = afs_iget(vnode->vfs_inode.i_sb, key,
 96				      &vnode->status.parent, NULL, NULL);
 97		if (IS_ERR(auth_inode))
 98			return ERR_CAST(auth_inode);
 99	}
100
101	auth_vnode = AFS_FS_I(auth_inode);
102	_leave(" = {%x}", auth_vnode->fid.vnode);
103	return auth_vnode;
104}
105
106/*
107 * clear the permit cache on a directory vnode
 
 
 
108 */
109void afs_clear_permits(struct afs_vnode *vnode)
 
110{
111	struct afs_permits *permits;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
113	_enter("{%x:%u}", vnode->fid.vid, vnode->fid.vnode);
 
 
 
114
115	mutex_lock(&vnode->permits_lock);
116	permits = vnode->permits;
117	rcu_assign_pointer(vnode->permits, NULL);
118	mutex_unlock(&vnode->permits_lock);
 
119
120	if (permits)
121		call_rcu(&permits->rcu, afs_zap_permits);
122	_leave("");
123}
124
125/*
126 * add the result obtained for a vnode to its or its parent directory's cache
127 * for the key used to access it
128 */
129void afs_cache_permit(struct afs_vnode *vnode, struct key *key, long acl_order)
130{
131	struct afs_permits *permits, *xpermits;
132	struct afs_permit *permit;
133	struct afs_vnode *auth_vnode;
134	int count, loop;
135
136	_enter("{%x:%u},%x,%lx",
137	       vnode->fid.vid, vnode->fid.vnode, key_serial(key), acl_order);
138
139	auth_vnode = afs_get_auth_inode(vnode, key);
140	if (IS_ERR(auth_vnode)) {
141		_leave(" [get error %ld]", PTR_ERR(auth_vnode));
142		return;
143	}
144
145	mutex_lock(&auth_vnode->permits_lock);
146
147	/* guard against a rename being detected whilst we waited for the
148	 * lock */
149	if (memcmp(&auth_vnode->fid, &vnode->status.parent,
150		   sizeof(struct afs_fid)) != 0) {
151		_debug("renamed");
152		goto out_unlock;
153	}
154
155	/* have to be careful as the directory's callback may be broken between
156	 * us receiving the status we're trying to cache and us getting the
157	 * lock to update the cache for the status */
158	if (auth_vnode->acl_order - acl_order > 0) {
159		_debug("ACL changed?");
160		goto out_unlock;
161	}
162
163	/* always update the anonymous mask */
164	_debug("anon access %x", vnode->status.anon_access);
165	auth_vnode->status.anon_access = vnode->status.anon_access;
166	if (key == vnode->volume->cell->anonymous_key)
167		goto out_unlock;
168
169	xpermits = auth_vnode->permits;
170	count = 0;
171	if (xpermits) {
172		/* see if the permit is already in the list
173		 * - if it is then we just amend the list
174		 */
175		count = xpermits->count;
176		permit = xpermits->permits;
177		for (loop = count; loop > 0; loop--) {
178			if (permit->key == key) {
179				permit->access_mask =
180					vnode->status.caller_access;
181				goto out_unlock;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182			}
183			permit++;
 
 
184		}
185	}
186
187	permits = kmalloc(sizeof(*permits) + sizeof(*permit) * (count + 1),
188			  GFP_NOFS);
189	if (!permits)
190		goto out_unlock;
191
192	if (xpermits)
193		memcpy(permits->permits, xpermits->permits,
194			count * sizeof(struct afs_permit));
195
196	_debug("key %x access %x",
197	       key_serial(key), vnode->status.caller_access);
198	permits->permits[count].access_mask = vnode->status.caller_access;
199	permits->permits[count].key = key_get(key);
200	permits->count = count + 1;
201
202	rcu_assign_pointer(auth_vnode->permits, permits);
203	if (xpermits)
204		call_rcu(&xpermits->rcu, afs_dispose_of_permits);
205
206out_unlock:
207	mutex_unlock(&auth_vnode->permits_lock);
208	iput(&auth_vnode->vfs_inode);
209	_leave("");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210}
211
212/*
213 * check with the fileserver to see if the directory or parent directory is
214 * permitted to be accessed with this authorisation, and if so, what access it
215 * is granted
216 */
217static int afs_check_permit(struct afs_vnode *vnode, struct key *key,
218			    afs_access_t *_access)
219{
220	struct afs_permits *permits;
221	struct afs_permit *permit;
222	struct afs_vnode *auth_vnode;
223	bool valid;
224	int loop, ret;
225
226	_enter("{%x:%u},%x",
227	       vnode->fid.vid, vnode->fid.vnode, key_serial(key));
228
229	auth_vnode = afs_get_auth_inode(vnode, key);
230	if (IS_ERR(auth_vnode)) {
231		*_access = 0;
232		_leave(" = %ld", PTR_ERR(auth_vnode));
233		return PTR_ERR(auth_vnode);
234	}
235
236	ASSERT(S_ISDIR(auth_vnode->vfs_inode.i_mode));
237
238	/* check the permits to see if we've got one yet */
239	if (key == auth_vnode->volume->cell->anonymous_key) {
240		_debug("anon");
241		*_access = auth_vnode->status.anon_access;
242		valid = true;
243	} else {
244		valid = false;
245		rcu_read_lock();
246		permits = rcu_dereference(auth_vnode->permits);
247		if (permits) {
248			permit = permits->permits;
249			for (loop = permits->count; loop > 0; loop--) {
250				if (permit->key == key) {
251					_debug("found in cache");
252					*_access = permit->access_mask;
253					valid = true;
254					break;
255				}
256				permit++;
 
 
257			}
258		}
259		rcu_read_unlock();
260	}
261
262	if (!valid) {
263		/* check the status on the file we're actually interested in
264		 * (the post-processing will cache the result on auth_vnode) */
 
265		_debug("no valid permit");
266
267		set_bit(AFS_VNODE_CB_BROKEN, &vnode->flags);
268		ret = afs_vnode_fetch_status(vnode, auth_vnode, key);
269		if (ret < 0) {
270			iput(&auth_vnode->vfs_inode);
271			*_access = 0;
272			_leave(" = %d", ret);
273			return ret;
274		}
275		*_access = vnode->status.caller_access;
276	}
277
278	iput(&auth_vnode->vfs_inode);
279	_leave(" = 0 [access %x]", *_access);
280	return 0;
281}
282
283/*
284 * check the permissions on an AFS file
285 * - AFS ACLs are attached to directories only, and a file is controlled by its
286 *   parent directory's ACL
287 */
288int afs_permission(struct inode *inode, int mask)
289{
290	struct afs_vnode *vnode = AFS_FS_I(inode);
291	afs_access_t uninitialized_var(access);
292	struct key *key;
293	int ret;
294
295	if (mask & MAY_NOT_BLOCK)
296		return -ECHILD;
297
298	_enter("{{%x:%u},%lx},%x,",
299	       vnode->fid.vid, vnode->fid.vnode, vnode->flags, mask);
300
301	key = afs_request_key(vnode->volume->cell);
302	if (IS_ERR(key)) {
303		_leave(" = %ld [key]", PTR_ERR(key));
304		return PTR_ERR(key);
305	}
306
307	/* if the promise has expired, we need to check the server again */
308	if (!vnode->cb_promised) {
309		_debug("not promised");
310		ret = afs_vnode_fetch_status(vnode, NULL, key);
311		if (ret < 0)
312			goto error;
313		_debug("new promise [fl=%lx]", vnode->flags);
314	}
315
316	/* check the permits to see if we've got one yet */
317	ret = afs_check_permit(vnode, key, &access);
318	if (ret < 0)
319		goto error;
320
321	/* interpret the access mask */
322	_debug("REQ %x ACC %x on %s",
323	       mask, access, S_ISDIR(inode->i_mode) ? "dir" : "file");
324
325	if (S_ISDIR(inode->i_mode)) {
326		if (mask & MAY_EXEC) {
327			if (!(access & AFS_ACE_LOOKUP))
328				goto permission_denied;
329		} else if (mask & MAY_READ) {
330			if (!(access & AFS_ACE_READ))
331				goto permission_denied;
332		} else if (mask & MAY_WRITE) {
333			if (!(access & (AFS_ACE_DELETE | /* rmdir, unlink, rename from */
334					AFS_ACE_INSERT | /* create, mkdir, symlink, rename to */
335					AFS_ACE_WRITE))) /* chmod */
336				goto permission_denied;
337		} else {
338			BUG();
339		}
340	} else {
341		if (!(access & AFS_ACE_LOOKUP))
342			goto permission_denied;
 
 
343		if (mask & (MAY_EXEC | MAY_READ)) {
344			if (!(access & AFS_ACE_READ))
345				goto permission_denied;
 
 
346		} else if (mask & MAY_WRITE) {
347			if (!(access & AFS_ACE_WRITE))
348				goto permission_denied;
 
 
349		}
350	}
351
352	key_put(key);
353	ret = generic_permission(inode, mask);
354	_leave(" = %d", ret);
355	return ret;
356
357permission_denied:
358	ret = -EACCES;
359error:
360	key_put(key);
361	_leave(" = %d", ret);
362	return ret;
 
 
 
 
 
 
 
 
 
363}