Skip to content

Commit

Permalink
ocfs2: Fix use of slab data with sendpage
Browse files Browse the repository at this point in the history
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 <[email protected]>
cc: Mark Fasheh <[email protected]>
cc: Kurt Hackel <[email protected]>
cc: Joel Becker <[email protected]>
cc: Joseph Qi <[email protected]>
cc: [email protected]
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
dhowells authored and kuba-moo committed Jun 24, 2023
1 parent d2fe210 commit 86d7bd6
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions fs/ocfs2/cluster/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2087,18 +2087,24 @@ void o2net_stop_listening(struct o2nm_node *node)

int o2net_init(void)
{
struct folio *folio;
void *p;
unsigned long i;

o2quo_init();

o2net_debugfs_init();

o2net_hand = kzalloc(sizeof(struct o2net_handshake), GFP_KERNEL);
o2net_keep_req = kzalloc(sizeof(struct o2net_msg), GFP_KERNEL);
o2net_keep_resp = kzalloc(sizeof(struct o2net_msg), GFP_KERNEL);
if (!o2net_hand || !o2net_keep_req || !o2net_keep_resp)
folio = folio_alloc(GFP_KERNEL | __GFP_ZERO, 0);
if (!folio)
goto out;

p = folio_address(folio);
o2net_hand = p;
p += sizeof(struct o2net_handshake);
o2net_keep_req = p;
p += sizeof(struct o2net_msg);
o2net_keep_resp = p;

o2net_hand->protocol_version = cpu_to_be64(O2NET_PROTOCOL_VERSION);
o2net_hand->connector_id = cpu_to_be64(1);

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

out:
kfree(o2net_hand);
kfree(o2net_keep_req);
kfree(o2net_keep_resp);
o2net_debugfs_exit();
o2quo_exit();
return -ENOMEM;
Expand All @@ -2135,8 +2138,6 @@ int o2net_init(void)
void o2net_exit(void)
{
o2quo_exit();
kfree(o2net_hand);
kfree(o2net_keep_req);
kfree(o2net_keep_resp);
o2net_debugfs_exit();
folio_put(virt_to_folio(o2net_hand));
}

0 comments on commit 86d7bd6

Please sign in to comment.