Commit 3ab0b245aa550ea4670d096092ca8e8d5e14ac89

Authored by Pablo Neira Ayuso
1 parent b236916a68

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>

Showing 1 changed file with 13 additions and 4 deletions Side-by-side Diff

net/netfilter/nfnetlink_acct.c
... ... @@ -166,7 +166,7 @@
166 166 nfnl_acct_get(struct sock *nfnl, struct sk_buff *skb,
167 167 const struct nlmsghdr *nlh, const struct nlattr * const tb[])
168 168 {
169   - int ret = 0;
  169 + int ret = -ENOENT;
170 170 struct nf_acct *cur;
171 171 char *acct_name;
172 172  
173 173  
174 174  
175 175  
176 176  
... ... @@ -186,17 +186,26 @@
186 186 continue;
187 187  
188 188 skb2 = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
189   - if (skb2 == NULL)
  189 + if (skb2 == NULL) {
  190 + ret = -ENOMEM;
190 191 break;
  192 + }
191 193  
192 194 ret = nfnl_acct_fill_info(skb2, NETLINK_CB(skb).pid,
193 195 nlh->nlmsg_seq,
194 196 NFNL_MSG_TYPE(nlh->nlmsg_type),
195 197 NFNL_MSG_ACCT_NEW, cur);
196   - if (ret <= 0)
  198 + if (ret <= 0) {
197 199 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;
198 206  
199   - break;
  207 + /* this avoids a loop in nfnetlink. */
  208 + return ret == -EAGAIN ? -ENOBUFS : ret;
200 209 }
201 210 return ret;
202 211 }