linux-audit.redhat.com archive mirror
 help / color / mirror / Atom feed
From: 亿一 <teroincn@gmail.com>
To: paul@paul-moore.com, eparis@redhat.com
Cc: linux-audit@redhat.com
Subject: kernel: audit.c: is it a memleak of net in function audit_send_reply
Date: Mon, 20 Apr 2020 15:54:16 +0800	[thread overview]
Message-ID: <CANTwqXCxk0_U2heNR0ua3Pb-ic=vsJj0Jot9z=3WhTMwfRKSag@mail.gmail.com> (raw)

Hi, all:

when reviewing code in function audit_send_reply, I notice that if
kthread_run return failure, the net reference would not be released
because reply has been kfree directly.

static void audit_send_reply(struct sk_buff *request_skb, int seq, int
type, int done,
     int multi, const void *payload, int size)
{
    struct net *net = sock_net(NETLINK_CB(request_skb).sk);
    struct sk_buff *skb;
    struct task_struct *tsk;
    struct audit_reply *reply = kmalloc(sizeof(struct audit_reply),
                                                           GFP_KERNEL);

    if (!reply)
        return;

    skb = audit_make_reply(seq, type, done, multi, payload, size);
    if (!skb)
        goto out;

    reply->net = get_net(net);     // hold a reference of net here
    reply->portid = NETLINK_CB(request_skb).portid;
    reply->skb = skb;

    tsk = kthread_run(audit_send_reply_thread, reply, "audit_send_reply");
    if (!IS_ERR(tsk))
        return;
    kfree_skb(skb);

    out:
        kfree(reply);      // kfree reply without release the net reference.
}


--
Linux-audit mailing list
Linux-audit@redhat.com
https://www.redhat.com/mailman/listinfo/linux-audit


             reply	other threads:[~2020-04-20 12:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-20  7:54 亿一 [this message]
2020-04-20 14:24 ` kernel: audit.c: is it a memleak of net in function audit_send_reply Paul Moore
2020-04-20 17:43   ` Paul Moore

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CANTwqXCxk0_U2heNR0ua3Pb-ic=vsJj0Jot9z=3WhTMwfRKSag@mail.gmail.com' \
    --to=teroincn@gmail.com \
    --cc=eparis@redhat.com \
    --cc=linux-audit@redhat.com \
    --cc=paul@paul-moore.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).