diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2016-03-28 00:30:35 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2016-03-31 00:27:32 -0400 |
commit | b1168a928277149e1c606763d76ff5c728988755 (patch) | |
tree | 1ad7c33f775ba3de1f576a244c09cfc7b7bb706e | |
parent | 0c93b7d85d40b690f04786ea0f18798b73182e4f (diff) |
ecryptfs: avoid multiple aliases for directories
ecryptfs_lookup_interpose should use d_splice_alias(), not d_add()
(and return struct dentry * rather than int). Get rid of
redundant dir_inode argument, while we are touching it...
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r-- | fs/ecryptfs/inode.c | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c index 121114e9a464..91ebc8f18e20 100644 --- a/fs/ecryptfs/inode.c +++ b/fs/ecryptfs/inode.c | |||
@@ -324,9 +324,8 @@ static int ecryptfs_i_size_read(struct dentry *dentry, struct inode *inode) | |||
324 | /** | 324 | /** |
325 | * ecryptfs_lookup_interpose - Dentry interposition for a lookup | 325 | * ecryptfs_lookup_interpose - Dentry interposition for a lookup |
326 | */ | 326 | */ |
327 | static int ecryptfs_lookup_interpose(struct dentry *dentry, | 327 | static struct dentry *ecryptfs_lookup_interpose(struct dentry *dentry, |
328 | struct dentry *lower_dentry, | 328 | struct dentry *lower_dentry) |
329 | struct inode *dir_inode) | ||
330 | { | 329 | { |
331 | struct inode *inode, *lower_inode = d_inode(lower_dentry); | 330 | struct inode *inode, *lower_inode = d_inode(lower_dentry); |
332 | struct ecryptfs_dentry_info *dentry_info; | 331 | struct ecryptfs_dentry_info *dentry_info; |
@@ -339,11 +338,12 @@ static int ecryptfs_lookup_interpose(struct dentry *dentry, | |||
339 | "to allocate ecryptfs_dentry_info struct\n", | 338 | "to allocate ecryptfs_dentry_info struct\n", |
340 | __func__); | 339 | __func__); |
341 | dput(lower_dentry); | 340 | dput(lower_dentry); |
342 | return -ENOMEM; | 341 | return ERR_PTR(-ENOMEM); |
343 | } | 342 | } |
344 | 343 | ||
345 | lower_mnt = mntget(ecryptfs_dentry_to_lower_mnt(dentry->d_parent)); | 344 | lower_mnt = mntget(ecryptfs_dentry_to_lower_mnt(dentry->d_parent)); |
346 | fsstack_copy_attr_atime(dir_inode, d_inode(lower_dentry->d_parent)); | 345 | fsstack_copy_attr_atime(d_inode(dentry->d_parent), |
346 | d_inode(lower_dentry->d_parent)); | ||
347 | BUG_ON(!d_count(lower_dentry)); | 347 | BUG_ON(!d_count(lower_dentry)); |
348 | 348 | ||
349 | ecryptfs_set_dentry_private(dentry, dentry_info); | 349 | ecryptfs_set_dentry_private(dentry, dentry_info); |
@@ -353,27 +353,25 @@ static int ecryptfs_lookup_interpose(struct dentry *dentry, | |||
353 | if (d_really_is_negative(lower_dentry)) { | 353 | if (d_really_is_negative(lower_dentry)) { |
354 | /* We want to add because we couldn't find in lower */ | 354 | /* We want to add because we couldn't find in lower */ |
355 | d_add(dentry, NULL); | 355 | d_add(dentry, NULL); |
356 | return 0; | 356 | return NULL; |
357 | } | 357 | } |
358 | inode = __ecryptfs_get_inode(lower_inode, dir_inode->i_sb); | 358 | inode = __ecryptfs_get_inode(lower_inode, dentry->d_sb); |
359 | if (IS_ERR(inode)) { | 359 | if (IS_ERR(inode)) { |
360 | printk(KERN_ERR "%s: Error interposing; rc = [%ld]\n", | 360 | printk(KERN_ERR "%s: Error interposing; rc = [%ld]\n", |
361 | __func__, PTR_ERR(inode)); | 361 | __func__, PTR_ERR(inode)); |
362 | return PTR_ERR(inode); | 362 | return ERR_CAST(inode); |
363 | } | 363 | } |
364 | if (S_ISREG(inode->i_mode)) { | 364 | if (S_ISREG(inode->i_mode)) { |
365 | rc = ecryptfs_i_size_read(dentry, inode); | 365 | rc = ecryptfs_i_size_read(dentry, inode); |
366 | if (rc) { | 366 | if (rc) { |
367 | make_bad_inode(inode); | 367 | make_bad_inode(inode); |
368 | return rc; | 368 | return ERR_PTR(rc); |
369 | } | 369 | } |
370 | } | 370 | } |
371 | 371 | ||
372 | if (inode->i_state & I_NEW) | 372 | if (inode->i_state & I_NEW) |
373 | unlock_new_inode(inode); | 373 | unlock_new_inode(inode); |
374 | d_add(dentry, inode); | 374 | return d_splice_alias(inode, dentry); |
375 | |||
376 | return rc; | ||
377 | } | 375 | } |
378 | 376 | ||
379 | /** | 377 | /** |
@@ -393,6 +391,7 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode, | |||
393 | size_t encrypted_and_encoded_name_size; | 391 | size_t encrypted_and_encoded_name_size; |
394 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat = NULL; | 392 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat = NULL; |
395 | struct dentry *lower_dir_dentry, *lower_dentry; | 393 | struct dentry *lower_dir_dentry, *lower_dentry; |
394 | struct dentry *res; | ||
396 | int rc = 0; | 395 | int rc = 0; |
397 | 396 | ||
398 | lower_dir_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry->d_parent); | 397 | lower_dir_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry->d_parent); |
@@ -400,10 +399,10 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode, | |||
400 | lower_dir_dentry, | 399 | lower_dir_dentry, |
401 | ecryptfs_dentry->d_name.len); | 400 | ecryptfs_dentry->d_name.len); |
402 | if (IS_ERR(lower_dentry)) { | 401 | if (IS_ERR(lower_dentry)) { |
403 | rc = PTR_ERR(lower_dentry); | ||
404 | ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned " | 402 | ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned " |
405 | "[%d] on lower_dentry = [%pd]\n", __func__, rc, | 403 | "[%ld] on lower_dentry = [%pd]\n", __func__, |
406 | ecryptfs_dentry); | 404 | PTR_ERR(lower_dentry), ecryptfs_dentry); |
405 | res = ERR_CAST(lower_dentry); | ||
407 | goto out; | 406 | goto out; |
408 | } | 407 | } |
409 | if (d_really_is_positive(lower_dentry)) | 408 | if (d_really_is_positive(lower_dentry)) |
@@ -421,24 +420,25 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode, | |||
421 | if (rc) { | 420 | if (rc) { |
422 | printk(KERN_ERR "%s: Error attempting to encrypt and encode " | 421 | printk(KERN_ERR "%s: Error attempting to encrypt and encode " |
423 | "filename; rc = [%d]\n", __func__, rc); | 422 | "filename; rc = [%d]\n", __func__, rc); |
423 | res = ERR_PTR(rc); | ||
424 | goto out; | 424 | goto out; |
425 | } | 425 | } |
426 | lower_dentry = lookup_one_len_unlocked(encrypted_and_encoded_name, | 426 | lower_dentry = lookup_one_len_unlocked(encrypted_and_encoded_name, |
427 | lower_dir_dentry, | 427 | lower_dir_dentry, |
428 | encrypted_and_encoded_name_size); | 428 | encrypted_and_encoded_name_size); |
429 | if (IS_ERR(lower_dentry)) { | 429 | if (IS_ERR(lower_dentry)) { |
430 | rc = PTR_ERR(lower_dentry); | ||
431 | ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned " | 430 | ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned " |
432 | "[%d] on lower_dentry = [%s]\n", __func__, rc, | 431 | "[%ld] on lower_dentry = [%s]\n", __func__, |
432 | PTR_ERR(lower_dentry), | ||
433 | encrypted_and_encoded_name); | 433 | encrypted_and_encoded_name); |
434 | res = ERR_CAST(lower_dentry); | ||
434 | goto out; | 435 | goto out; |
435 | } | 436 | } |
436 | interpose: | 437 | interpose: |
437 | rc = ecryptfs_lookup_interpose(ecryptfs_dentry, lower_dentry, | 438 | res = ecryptfs_lookup_interpose(ecryptfs_dentry, lower_dentry); |
438 | ecryptfs_dir_inode); | ||
439 | out: | 439 | out: |
440 | kfree(encrypted_and_encoded_name); | 440 | kfree(encrypted_and_encoded_name); |
441 | return ERR_PTR(rc); | 441 | return res; |
442 | } | 442 | } |
443 | 443 | ||
444 | static int ecryptfs_link(struct dentry *old_dentry, struct inode *dir, | 444 | static int ecryptfs_link(struct dentry *old_dentry, struct inode *dir, |