From: Dan Carpenter <dan.carpenter@oracle.com>
To: kbuild@01.org
Cc: Jan Kara <jack@suse.cz>, Paul Moore <paul@paul-moore.com>,
Richard Guy Briggs <rgb@redhat.com>,
linux-audit@redhat.com, kbuild-all@01.org,
linux-fsdevel@vger.kernel.org, Al Viro <viro@ZenIV.linux.org.uk>
Subject: Re: [PATCH 2/6] audit: Fix possible spurious -ENOSPC error
Date: Mon, 2 Jul 2018 09:05:49 +0300 [thread overview]
Message-ID: <20180702060549.cpwsc4byshuvqrx7@mwanda> (raw)
In-Reply-To: <20180628164014.4925-3-jack@suse.cz>
Hi Jan,
url: https://github.com/0day-ci/linux/commits/Jan-Kara/audit-Fix-various-races-when-tagging-and-untagging-mounts/20180629-043337
smatch warnings:
kernel/audit_tree.c:484 tag_chunk() warn: inconsistent returns 'mutex:&audit_tree_group->mark_mutex'.
Locked on: line 400
Unlocked on: line 411
# https://github.com/0day-ci/linux/commit/86c9c9a738e409c85891519c17d94043b7f434d5
git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout 86c9c9a738e409c85891519c17d94043b7f434d5
vim +484 kernel/audit_tree.c
74c3cbe33 Al Viro 2007-07-22 386
74c3cbe33 Al Viro 2007-07-22 387 /* the first tagged inode becomes root of tree */
74c3cbe33 Al Viro 2007-07-22 388 static int tag_chunk(struct inode *inode, struct audit_tree *tree)
74c3cbe33 Al Viro 2007-07-22 389 {
e61ce8673 Eric Paris 2009-12-17 390 struct fsnotify_mark *old_entry, *chunk_entry;
74c3cbe33 Al Viro 2007-07-22 391 struct audit_tree *owner;
74c3cbe33 Al Viro 2007-07-22 392 struct audit_chunk *chunk, *old;
74c3cbe33 Al Viro 2007-07-22 393 struct node *p;
74c3cbe33 Al Viro 2007-07-22 394 int n;
74c3cbe33 Al Viro 2007-07-22 395
86c9c9a73 Jan Kara 2018-06-28 396 mutex_lock(&audit_tree_group->mark_mutex);
b1362edfe Jan Kara 2016-12-21 397 old_entry = fsnotify_find_mark(&inode->i_fsnotify_marks,
b1362edfe Jan Kara 2016-12-21 398 audit_tree_group);
28a3a7eb3 Eric Paris 2009-12-17 399 if (!old_entry)
74c3cbe33 Al Viro 2007-07-22 400 return create_chunk(inode, tree);
^^^^^^^^^^^^^^^^^^^^^^^^^
Should we drop the lock before this return?
74c3cbe33 Al Viro 2007-07-22 401
28a3a7eb3 Eric Paris 2009-12-17 402 old = container_of(old_entry, struct audit_chunk, mark);
74c3cbe33 Al Viro 2007-07-22 403
74c3cbe33 Al Viro 2007-07-22 404 /* are we already there? */
74c3cbe33 Al Viro 2007-07-22 405 spin_lock(&hash_lock);
74c3cbe33 Al Viro 2007-07-22 406 for (n = 0; n < old->count; n++) {
74c3cbe33 Al Viro 2007-07-22 407 if (old->owners[n].owner == tree) {
74c3cbe33 Al Viro 2007-07-22 408 spin_unlock(&hash_lock);
86c9c9a73 Jan Kara 2018-06-28 409 mutex_unlock(&audit_tree_group->mark_mutex);
28a3a7eb3 Eric Paris 2009-12-17 410 fsnotify_put_mark(old_entry);
74c3cbe33 Al Viro 2007-07-22 411 return 0;
74c3cbe33 Al Viro 2007-07-22 412 }
74c3cbe33 Al Viro 2007-07-22 413 }
74c3cbe33 Al Viro 2007-07-22 414 spin_unlock(&hash_lock);
74c3cbe33 Al Viro 2007-07-22 415
74c3cbe33 Al Viro 2007-07-22 416 chunk = alloc_chunk(old->count + 1);
b4c30aad3 Al Viro 2009-12-19 417 if (!chunk) {
86c9c9a73 Jan Kara 2018-06-28 418 mutex_unlock(&audit_tree_group->mark_mutex);
28a3a7eb3 Eric Paris 2009-12-17 419 fsnotify_put_mark(old_entry);
74c3cbe33 Al Viro 2007-07-22 420 return -ENOMEM;
b4c30aad3 Al Viro 2009-12-19 421 }
74c3cbe33 Al Viro 2007-07-22 422
28a3a7eb3 Eric Paris 2009-12-17 423 chunk_entry = &chunk->mark;
28a3a7eb3 Eric Paris 2009-12-17 424
6b3f05d24 Jan Kara 2016-12-21 425 /*
6b3f05d24 Jan Kara 2016-12-21 426 * mark_mutex protects mark from getting detached and thus also from
36f10f55f Amir Goldstein 2018-06-23 427 * mark->connector->obj getting NULL.
6b3f05d24 Jan Kara 2016-12-21 428 */
43471d15d Jan Kara 2017-04-03 429 if (!(old_entry->flags & FSNOTIFY_MARK_FLAG_ATTACHED)) {
28a3a7eb3 Eric Paris 2009-12-17 430 /* old_entry is being shot, lets just lie */
86c9c9a73 Jan Kara 2018-06-28 431 mutex_unlock(&audit_tree_group->mark_mutex);
28a3a7eb3 Eric Paris 2009-12-17 432 fsnotify_put_mark(old_entry);
7b1293234 Jan Kara 2016-12-21 433 fsnotify_put_mark(&chunk->mark);
28a3a7eb3 Eric Paris 2009-12-17 434 return -ENOENT;
28a3a7eb3 Eric Paris 2009-12-17 435 }
28a3a7eb3 Eric Paris 2009-12-17 436
36f10f55f Amir Goldstein 2018-06-23 437 if (fsnotify_add_mark_locked(chunk_entry, old_entry->connector->obj,
36f10f55f Amir Goldstein 2018-06-23 438 FSNOTIFY_OBJ_TYPE_INODE, 1)) {
86c9c9a73 Jan Kara 2018-06-28 439 mutex_unlock(&audit_tree_group->mark_mutex);
0fe33aae0 Miklos Szeredi 2012-08-15 440 fsnotify_put_mark(chunk_entry);
28a3a7eb3 Eric Paris 2009-12-17 441 fsnotify_put_mark(old_entry);
74c3cbe33 Al Viro 2007-07-22 442 return -ENOSPC;
74c3cbe33 Al Viro 2007-07-22 443 }
28a3a7eb3 Eric Paris 2009-12-17 444
74c3cbe33 Al Viro 2007-07-22 445 spin_lock(&hash_lock);
74c3cbe33 Al Viro 2007-07-22 446 if (tree->goner) {
74c3cbe33 Al Viro 2007-07-22 447 spin_unlock(&hash_lock);
74c3cbe33 Al Viro 2007-07-22 448 chunk->dead = 1;
86c9c9a73 Jan Kara 2018-06-28 449 mutex_unlock(&audit_tree_group->mark_mutex);
28a3a7eb3 Eric Paris 2009-12-17 450
e2a29943e Lino Sanfilippo 2011-06-14 451 fsnotify_destroy_mark(chunk_entry, audit_tree_group);
28a3a7eb3 Eric Paris 2009-12-17 452
28a3a7eb3 Eric Paris 2009-12-17 453 fsnotify_put_mark(chunk_entry);
28a3a7eb3 Eric Paris 2009-12-17 454 fsnotify_put_mark(old_entry);
74c3cbe33 Al Viro 2007-07-22 455 return 0;
74c3cbe33 Al Viro 2007-07-22 456 }
74c3cbe33 Al Viro 2007-07-22 457 list_replace_init(&old->trees, &chunk->trees);
74c3cbe33 Al Viro 2007-07-22 458 for (n = 0, p = chunk->owners; n < old->count; n++, p++) {
74c3cbe33 Al Viro 2007-07-22 459 struct audit_tree *s = old->owners[n].owner;
74c3cbe33 Al Viro 2007-07-22 460 p->owner = s;
74c3cbe33 Al Viro 2007-07-22 461 p->index = old->owners[n].index;
74c3cbe33 Al Viro 2007-07-22 462 if (!s) /* result of fallback in untag */
74c3cbe33 Al Viro 2007-07-22 463 continue;
74c3cbe33 Al Viro 2007-07-22 464 get_tree(s);
74c3cbe33 Al Viro 2007-07-22 465 list_replace_init(&old->owners[n].list, &p->list);
74c3cbe33 Al Viro 2007-07-22 466 }
74c3cbe33 Al Viro 2007-07-22 467 p->index = (chunk->count - 1) | (1U<<31);
74c3cbe33 Al Viro 2007-07-22 468 p->owner = tree;
74c3cbe33 Al Viro 2007-07-22 469 get_tree(tree);
74c3cbe33 Al Viro 2007-07-22 470 list_add(&p->list, &tree->chunks);
74c3cbe33 Al Viro 2007-07-22 471 list_replace_rcu(&old->hash, &chunk->hash);
74c3cbe33 Al Viro 2007-07-22 472 list_for_each_entry(owner, &chunk->trees, same_root)
74c3cbe33 Al Viro 2007-07-22 473 owner->root = chunk;
74c3cbe33 Al Viro 2007-07-22 474 old->dead = 1;
74c3cbe33 Al Viro 2007-07-22 475 if (!tree->root) {
74c3cbe33 Al Viro 2007-07-22 476 tree->root = chunk;
74c3cbe33 Al Viro 2007-07-22 477 list_add(&tree->same_root, &chunk->trees);
74c3cbe33 Al Viro 2007-07-22 478 }
74c3cbe33 Al Viro 2007-07-22 479 spin_unlock(&hash_lock);
86c9c9a73 Jan Kara 2018-06-28 480 mutex_unlock(&audit_tree_group->mark_mutex);
e2a29943e Lino Sanfilippo 2011-06-14 481 fsnotify_destroy_mark(old_entry, audit_tree_group);
b3e8692b4 Miklos Szeredi 2012-08-15 482 fsnotify_put_mark(chunk_entry); /* drop initial reference */
28a3a7eb3 Eric Paris 2009-12-17 483 fsnotify_put_mark(old_entry); /* pair to fsnotify_find mark_entry */
74c3cbe33 Al Viro 2007-07-22 @484 return 0;
74c3cbe33 Al Viro 2007-07-22 485 }
74c3cbe33 Al Viro 2007-07-22 486
:::::: The code at line 484 was first introduced by commit
:::::: 74c3cbe33bc077ac1159cadfea608b501e100344 [PATCH] audit: watching subtrees
:::::: TO: Al Viro <viro@zeniv.linux.org.uk>
:::::: CC: Al Viro <viro@zeniv.linux.org.uk>
next prev parent reply other threads:[~2018-07-02 6:05 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-28 16:40 [PATCH 0/6] audit: Fix various races when tagging and untagging mounts Jan Kara
2018-06-28 16:40 ` [PATCH 1/6] audit_tree: Replace mark->lock locking Jan Kara
2018-06-29 11:31 ` Amir Goldstein
2018-07-03 14:07 ` Jan Kara
2018-06-28 16:40 ` [PATCH 2/6] audit: Fix possible spurious -ENOSPC error Jan Kara
2018-06-29 11:42 ` Amir Goldstein
2018-07-02 6:05 ` Dan Carpenter [this message]
2018-07-03 14:18 ` Jan Kara
2018-06-28 16:40 ` [PATCH 3/6] audit: Fix possible tagging failures Jan Kara
2018-06-29 12:05 ` Amir Goldstein
2018-07-03 14:21 ` Jan Kara
2018-07-03 17:42 ` Amir Goldstein
2018-07-04 8:28 ` Jan Kara
2018-06-28 16:40 ` [PATCH 4/6] audit: Embed key into chunk Jan Kara
2018-06-29 12:53 ` Amir Goldstein
2018-07-03 14:25 ` Jan Kara
2018-06-28 16:40 ` [PATCH 5/6] audit: Make hash table insertion safe against concurrent lookups Jan Kara
2018-06-29 13:02 ` Amir Goldstein
2018-07-03 15:31 ` Jan Kara
2018-06-28 16:40 ` [PATCH 6/6] audit: Point to fsnotify mark instead of embedding it Jan Kara
2018-06-29 13:20 ` Amir Goldstein
2018-07-04 12:34 ` Jan Kara
2018-06-29 11:44 ` [PATCH 0/6] audit: Fix various races when tagging and untagging mounts Amir Goldstein
2018-06-29 18:01 ` Paul Moore
2018-07-03 14:14 ` Jan Kara
2018-07-03 17:03 ` Paul Moore
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180702060549.cpwsc4byshuvqrx7@mwanda \
--to=dan.carpenter@oracle.com \
--cc=jack@suse.cz \
--cc=kbuild-all@01.org \
--cc=kbuild@01.org \
--cc=linux-audit@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=rgb@redhat.com \
--cc=viro@ZenIV.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox