Skip to content

Commit 86d7bd6

Browse files
dhowellskuba-moo
authored andcommitted
ocfs2: Fix use of slab data with sendpage
ocfs2 uses kzalloc() to allocate buffers for o2net_hand, o2net_keep_req and o2net_keep_resp and then passes these to sendpage. This isn't really allowed as the lifetime of slab objects is not controlled by page ref - though in this case it will probably work. sendmsg() with MSG_SPLICE_PAGES will, however, print a warning and give an error. Fix it to use folio_alloc() instead to allocate a buffer for the handshake message, keepalive request and reply messages. Fixes: 9821148 ("[PATCH] OCFS2: The Second Oracle Cluster Filesystem") Signed-off-by: David Howells <dhowells@redhat.com> cc: Mark Fasheh <mark@fasheh.com> cc: Kurt Hackel <kurt.hackel@oracle.com> cc: Joel Becker <jlbec@evilplan.org> cc: Joseph Qi <joseph.qi@linux.alibaba.com> cc: ocfs2-devel@oss.oracle.com Link: https://lore.kernel.org/r/20230623225513.2732256-14-dhowells@redhat.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent d2fe210 commit 86d7bd6

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

fs/ocfs2/cluster/tcp.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,18 +2087,24 @@ void o2net_stop_listening(struct o2nm_node *node)
20872087

20882088
int o2net_init(void)
20892089
{
2090+
struct folio *folio;
2091+
void *p;
20902092
unsigned long i;
20912093

20922094
o2quo_init();
2093-
20942095
o2net_debugfs_init();
20952096

2096-
o2net_hand = kzalloc(sizeof(struct o2net_handshake), GFP_KERNEL);
2097-
o2net_keep_req = kzalloc(sizeof(struct o2net_msg), GFP_KERNEL);
2098-
o2net_keep_resp = kzalloc(sizeof(struct o2net_msg), GFP_KERNEL);
2099-
if (!o2net_hand || !o2net_keep_req || !o2net_keep_resp)
2097+
folio = folio_alloc(GFP_KERNEL | __GFP_ZERO, 0);
2098+
if (!folio)
21002099
goto out;
21012100

2101+
p = folio_address(folio);
2102+
o2net_hand = p;
2103+
p += sizeof(struct o2net_handshake);
2104+
o2net_keep_req = p;
2105+
p += sizeof(struct o2net_msg);
2106+
o2net_keep_resp = p;
2107+
21022108
o2net_hand->protocol_version = cpu_to_be64(O2NET_PROTOCOL_VERSION);
21032109
o2net_hand->connector_id = cpu_to_be64(1);
21042110

@@ -2124,9 +2130,6 @@ int o2net_init(void)
21242130
return 0;
21252131

21262132
out:
2127-
kfree(o2net_hand);
2128-
kfree(o2net_keep_req);
2129-
kfree(o2net_keep_resp);
21302133
o2net_debugfs_exit();
21312134
o2quo_exit();
21322135
return -ENOMEM;
@@ -2135,8 +2138,6 @@ int o2net_init(void)
21352138
void o2net_exit(void)
21362139
{
21372140
o2quo_exit();
2138-
kfree(o2net_hand);
2139-
kfree(o2net_keep_req);
2140-
kfree(o2net_keep_resp);
21412141
o2net_debugfs_exit();
2142+
folio_put(virt_to_folio(o2net_hand));
21422143
}

0 commit comments

Comments
 (0)