Skip to content

Commit 4245a79

Browse files
Yuuoniykuba-moo
authored andcommitted
rxrpc, afs: Fix missing error pointer check after rxrpc_kernel_lookup_peer()
rxrpc_kernel_lookup_peer() can also return error pointers in addition to NULL, so just checking for NULL is not sufficient. Fix this by: (1) Changing rxrpc_kernel_lookup_peer() to return -ENOMEM rather than NULL on allocation failure. (2) Making the callers in afs use IS_ERR() and PTR_ERR() to pass on the error code returned. Fixes: 72904d7 ("rxrpc, afs: Allow afs to pin rxrpc_peer objects") Signed-off-by: Miaoqian Lin <[email protected]> Co-developed-by: David Howells <[email protected]> Signed-off-by: David Howells <[email protected]> cc: Marc Dionne <[email protected]> cc: Simon Horman <[email protected]> cc: [email protected] Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 7a4d746 commit 4245a79

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

fs/afs/addr_list.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ int afs_merge_fs_addr4(struct afs_net *net, struct afs_addr_list *alist,
298298
srx.transport.sin.sin_addr.s_addr = xdr;
299299

300300
peer = rxrpc_kernel_lookup_peer(net->socket, &srx, GFP_KERNEL);
301-
if (!peer)
302-
return -ENOMEM;
301+
if (IS_ERR(peer))
302+
return PTR_ERR(peer);
303303

304304
for (i = 0; i < alist->nr_ipv4; i++) {
305305
if (peer == alist->addrs[i].peer) {
@@ -342,8 +342,8 @@ int afs_merge_fs_addr6(struct afs_net *net, struct afs_addr_list *alist,
342342
memcpy(&srx.transport.sin6.sin6_addr, xdr, 16);
343343

344344
peer = rxrpc_kernel_lookup_peer(net->socket, &srx, GFP_KERNEL);
345-
if (!peer)
346-
return -ENOMEM;
345+
if (IS_ERR(peer))
346+
return PTR_ERR(peer);
347347

348348
for (i = alist->nr_ipv4; i < alist->nr_addrs; i++) {
349349
if (peer == alist->addrs[i].peer) {

net/rxrpc/af_rxrpc.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,20 +267,22 @@ static int rxrpc_listen(struct socket *sock, int backlog)
267267
* Lookup or create a remote transport endpoint record for the specified
268268
* address.
269269
*
270-
* Return: The peer record found with a reference, %NULL if no record is found
271-
* or a negative error code if the address is invalid or unsupported.
270+
* Return: The peer record found with a reference or a negative error code if
271+
* the address is invalid or unsupported.
272272
*/
273273
struct rxrpc_peer *rxrpc_kernel_lookup_peer(struct socket *sock,
274274
struct sockaddr_rxrpc *srx, gfp_t gfp)
275275
{
276+
struct rxrpc_peer *peer;
276277
struct rxrpc_sock *rx = rxrpc_sk(sock->sk);
277278
int ret;
278279

279280
ret = rxrpc_validate_address(rx, srx, sizeof(*srx));
280281
if (ret < 0)
281282
return ERR_PTR(ret);
282283

283-
return rxrpc_lookup_peer(rx->local, srx, gfp);
284+
peer = rxrpc_lookup_peer(rx->local, srx, gfp);
285+
return peer ?: ERR_PTR(-ENOMEM);
284286
}
285287
EXPORT_SYMBOL(rxrpc_kernel_lookup_peer);
286288

0 commit comments

Comments
 (0)