Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ea7ae60b authored by Eric Paris's avatar Eric Paris Committed by Al Viro
Browse files

Audit: clean up audit_receive_skb



audit_receive_skb is hard to clearly parse what it is doing to the netlink
message.  Clean the function up so it is easy and clear to see what is going
on.

Signed-off-by: default avatarEric Paris <eparis@redhat.com>
parent ee080e6c
Loading
Loading
Loading
Loading
+18 −17
Original line number Original line Diff line number Diff line
@@ -937,28 +937,29 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
}
}


/*
/*
 * Get message from skb (based on rtnetlink_rcv_skb).  Each message is
 * Get message from skb.  Each message is processed by audit_receive_msg.
 * processed by audit_receive_msg.  Malformed skbs with wrong length are
 * Malformed skbs with wrong length are discarded silently.
 * discarded silently.
 */
 */
static void audit_receive_skb(struct sk_buff *skb)
static void audit_receive_skb(struct sk_buff *skb)
{
{
	int		err;
	struct nlmsghdr *nlh;
	struct nlmsghdr *nlh;
	u32		rlen;
	/*
	 * len MUST be signed for NLMSG_NEXT to be able to dec it below 0
	 * if the nlmsg_len was not aligned
	 */
	int len;
	int err;


	while (skb->len >= NLMSG_SPACE(0)) {
	nlh = nlmsg_hdr(skb);
	nlh = nlmsg_hdr(skb);
		if (nlh->nlmsg_len < sizeof(*nlh) || skb->len < nlh->nlmsg_len)
	len = skb->len;
			return;

		rlen = NLMSG_ALIGN(nlh->nlmsg_len);
	while (NLMSG_OK(nlh, len)) {
		if (rlen > skb->len)
		err = audit_receive_msg(skb, nlh);
			rlen = skb->len;
		/* if err or if this message says it wants a response */
		if ((err = audit_receive_msg(skb, nlh))) {
		if (err || (nlh->nlmsg_flags & NLM_F_ACK))
			netlink_ack(skb, nlh, err);
			netlink_ack(skb, nlh, err);
		} else if (nlh->nlmsg_flags & NLM_F_ACK)

			netlink_ack(skb, nlh, 0);
		nlh = NLMSG_NEXT(nlh, len);
		skb_pull(skb, rlen);
	}
	}
}
}