linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hfsplus: fix segfault when deleting all attrs of a file
@ 2017-10-06 21:52 Ernesto A. Fernández
  2017-10-07  5:03 ` Viacheslav Dubeyko
  0 siblings, 1 reply; 11+ messages in thread
From: Ernesto A. Fernández @ 2017-10-06 21:52 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: Sergei Antonov, Vyacheslav Dubeyko, Hin-Tak Leung, Al Viro,
	Christoph Hellwig, Ernesto A. Fernández

A segmentation fault can be triggered by setting many xattrs to a file
and then deleting it. The number must be high enough for more than one
b-tree node to be needed for storage.

When hfs_brec_remove() is called as part of hfsplus_delete_all_attrs(),
fd->search_key will not be set to any specific value. It does not matter
because we intend to remove all records for a given cnid.

The problem is that hfs_brec_remove() assumes it is being called with
the result of a search by key, not by cnid. The value of search_key may
be used to update the parent nodes. When no appropriate parent record is
found, the result is an out of bounds access.

To fix this, set the value of fd->search_key to the key of the first
record in the node, which is also the key of the corresponding parent
record.

Signed-off-by: Ernesto A. Fernández <ernesto.mnd.fernandez@gmail.com>
---
 fs/hfsplus/brec.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/hfsplus/brec.c b/fs/hfsplus/brec.c
index 754fdf8..dfa60cf 100644
--- a/fs/hfsplus/brec.c
+++ b/fs/hfsplus/brec.c
@@ -182,6 +182,9 @@ int hfs_brec_remove(struct hfs_find_data *fd)
 
 	tree = fd->tree;
 	node = fd->bnode;
+
+	/* in case we need to search the parent node */
+	hfs_bnode_read_key(node, fd->search_key, 14);
 again:
 	rec_off = tree->node_size - (fd->record + 2) * 2;
 	end_off = tree->node_size - (node->num_recs + 1) * 2;
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 11+ messages in thread
[parent not found: <1676784878.5173672.1507350322487.ref@mail.yahoo.com>]
[parent not found: <1601904757.6392039.1507492617972.ref@mail.yahoo.com>]

end of thread, other threads:[~2017-10-11  4:43 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-06 21:52 [PATCH] hfsplus: fix segfault when deleting all attrs of a file Ernesto A. Fernández
2017-10-07  5:03 ` Viacheslav Dubeyko
2017-10-08 19:46   ` Ernesto A. Fernández
2017-10-09 17:03     ` Viacheslav Dubeyko
2017-10-09 19:59       ` Ernesto A. Fernández
2017-10-10 15:07         ` Viacheslav Dubeyko
2017-10-10 21:39         ` Slava Dubeyko
2017-10-11  4:43           ` Ernesto A. Fernández
     [not found] <1676784878.5173672.1507350322487.ref@mail.yahoo.com>
2017-10-07  4:25 ` Hin-Tak Leung
2017-10-08 18:51   ` Ernesto A. Fernández
     [not found] <1601904757.6392039.1507492617972.ref@mail.yahoo.com>
2017-10-08 19:56 ` Hin-Tak Leung

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).