Skip to content

Commit 9f8eeea

Browse files
Yunsheng Linkuba-moo
authored andcommitted
rxrpc: Fix using alignmask being zero for __page_frag_alloc_align()
rxrpc_alloc_data_txbuf() may be called with data_align being zero in none_alloc_txbuf() and rxkad_alloc_txbuf(), data_align is supposed to be an order-based alignment value, but zero is not a valid order-based alignment value, and '~(data_align - 1)' doesn't result in a valid mask-based alignment value for __page_frag_alloc_align(). Fix it by passing a valid order-based alignment value in none_alloc_txbuf() and rxkad_alloc_txbuf(). Also use page_frag_alloc_align() expecting an order-based alignment value in rxrpc_alloc_data_txbuf() to avoid doing the alignment converting operation and to catch possible invalid alignment value in the future. Remove the 'if (data_align)' checking too, as it is always true for a valid order-based alignment value. Fixes: 6b25364 ("rxrpc: Fix use of changed alignment param to page_frag_alloc_align()") Fixes: 49489bb ("rxrpc: Do zerocopy using MSG_SPLICE_PAGES and page frags") CC: Alexander Duyck <alexander.duyck@gmail.com> Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com> Acked-by: David Howells <dhowells@redhat.com> Link: https://lore.kernel.org/r/20240428111640.27306-1-linyunsheng@huawei.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent ba1cb99 commit 9f8eeea

3 files changed

Lines changed: 7 additions & 7 deletions

File tree

net/rxrpc/insecure.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static int none_init_connection_security(struct rxrpc_connection *conn,
1919
*/
2020
static struct rxrpc_txbuf *none_alloc_txbuf(struct rxrpc_call *call, size_t remain, gfp_t gfp)
2121
{
22-
return rxrpc_alloc_data_txbuf(call, min_t(size_t, remain, RXRPC_JUMBO_DATALEN), 0, gfp);
22+
return rxrpc_alloc_data_txbuf(call, min_t(size_t, remain, RXRPC_JUMBO_DATALEN), 1, gfp);
2323
}
2424

2525
static int none_secure_packet(struct rxrpc_call *call, struct rxrpc_txbuf *txb)

net/rxrpc/rxkad.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ static struct rxrpc_txbuf *rxkad_alloc_txbuf(struct rxrpc_call *call, size_t rem
155155
switch (call->conn->security_level) {
156156
default:
157157
space = min_t(size_t, remain, RXRPC_JUMBO_DATALEN);
158-
return rxrpc_alloc_data_txbuf(call, space, 0, gfp);
158+
return rxrpc_alloc_data_txbuf(call, space, 1, gfp);
159159
case RXRPC_SECURITY_AUTH:
160160
shdr = sizeof(struct rxkad_level1_hdr);
161161
break;

net/rxrpc/txbuf.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ struct rxrpc_txbuf *rxrpc_alloc_data_txbuf(struct rxrpc_call *call, size_t data_
2121
{
2222
struct rxrpc_wire_header *whdr;
2323
struct rxrpc_txbuf *txb;
24-
size_t total, hoff = 0;
24+
size_t total, hoff;
2525
void *buf;
2626

2727
txb = kmalloc(sizeof(*txb), gfp);
2828
if (!txb)
2929
return NULL;
3030

31-
if (data_align)
32-
hoff = round_up(sizeof(*whdr), data_align) - sizeof(*whdr);
31+
hoff = round_up(sizeof(*whdr), data_align) - sizeof(*whdr);
3332
total = hoff + sizeof(*whdr) + data_size;
3433

34+
data_align = umax(data_align, L1_CACHE_BYTES);
3535
mutex_lock(&call->conn->tx_data_alloc_lock);
36-
buf = __page_frag_alloc_align(&call->conn->tx_data_alloc, total, gfp,
37-
~(data_align - 1) & ~(L1_CACHE_BYTES - 1));
36+
buf = page_frag_alloc_align(&call->conn->tx_data_alloc, total, gfp,
37+
data_align);
3838
mutex_unlock(&call->conn->tx_data_alloc_lock);
3939
if (!buf) {
4040
kfree(txb);

0 commit comments

Comments
 (0)