Skip to content

Commit 3ab0b24

Browse files
committed
netfilter: nfnetlink_acct: fix nfnl_acct_get operation
The get operation was not sending the message that was built to user-space. This patch also includes the appropriate handling for the return value of netlink_unicast(). Moreover, fix error codes on error (for example, for non-existing entry was uncorrect). Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent b236916 commit 3ab0b24

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

‎net/netfilter/nfnetlink_acct.c‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ static int
166166
nfnl_acct_get(struct sock *nfnl, struct sk_buff *skb,
167167
const struct nlmsghdr *nlh, const struct nlattr * const tb[])
168168
{
169-
int ret = 0;
169+
int ret = -ENOENT;
170170
struct nf_acct *cur;
171171
char *acct_name;
172172

@@ -186,17 +186,26 @@ nfnl_acct_get(struct sock *nfnl, struct sk_buff *skb,
186186
continue;
187187

188188
skb2 = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
189-
if (skb2 == NULL)
189+
if (skb2 == NULL) {
190+
ret = -ENOMEM;
190191
break;
192+
}
191193

192194
ret = nfnl_acct_fill_info(skb2, NETLINK_CB(skb).pid,
193195
nlh->nlmsg_seq,
194196
NFNL_MSG_TYPE(nlh->nlmsg_type),
195197
NFNL_MSG_ACCT_NEW, cur);
196-
if (ret <= 0)
198+
if (ret <= 0) {
197199
kfree_skb(skb2);
200+
break;
201+
}
202+
ret = netlink_unicast(nfnl, skb2, NETLINK_CB(skb).pid,
203+
MSG_DONTWAIT);
204+
if (ret > 0)
205+
ret = 0;
198206

199-
break;
207+
/* this avoids a loop in nfnetlink. */
208+
return ret == -EAGAIN ? -ENOBUFS : ret;
200209
}
201210
return ret;
202211
}

0 commit comments

Comments
 (0)