mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: baijiaju1990@gmail.com
Cc: ktkhai@virtuozzo.com, viro@zeniv.linux.org.uk,
	adobriyan@gmail.com, dvlasenk@redhat.com,
	xiyou.wangcong@gmail.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] net: scm: Fix a possible sleep-in-atomic-context bug in scm_fp_copy()
Date: Sun, 02 Sep 2018 16:01:44 -0700 (PDT)	[thread overview]
Message-ID: <20180902.160144.542360312136980090.davem@davemloft.net> (raw)
In-Reply-To: <20180901100026.16956-1-baijiaju1990@gmail.com>

From: Jia-Ju Bai <baijiaju1990@gmail.com>
Date: Sat,  1 Sep 2018 18:00:26 +0800

> The kernel module may sleep with holding a spinlock.
> 
> The function call paths (from bottom to top) in Linux-4.16 are:
> 
> [FUNC] kmalloc(GFP_KERNEL)
> net/core/scm.c, 85: kmalloc in scm_fp_copy
> net/core/scm.c, 161: scm_fp_copy in __scm_send
> ./include/net/scm.h, 88: __scm_send in scm_send
> net/unix/af_unix.c, 1600: scm_send in maybe_init_creds
> net/unix/af_unix.c, 1983: maybe_init_creds in unix_stream_sendpage
> net/unix/af_unix.c, 1973: spin_lock in unix_stream_sendpage

Please, do a full analysis of the code for these changes you are
submitting.

Read maybe_init_creds(), it sets msg.msg_controllen to zero.

	struct msghdr msg = { .msg_controllen = 0 };

When that is zero, __scm__send() is never called.

static __inline__ int scm_send(struct socket *sock, struct msghdr *msg,
			       struct scm_cookie *scm, bool forcecreds)
{
 ...
	if (msg->msg_controllen <= 0)
		return 0;
	return __scm_send(sock, msg, scm);

If this bug existed, sleeping in atomic warnings would be triggering
all the time and people would report that.

  reply	other threads:[~2018-09-02 23:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-01 10:00 Jia-Ju Bai
2018-09-02 23:01 ` David Miller [this message]
2018-09-03  1:43   ` Jia-Ju Bai

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=20180902.160144.542360312136980090.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=adobriyan@gmail.com \
    --cc=baijiaju1990@gmail.com \
    --cc=dvlasenk@redhat.com \
    --cc=ktkhai@virtuozzo.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=xiyou.wangcong@gmail.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

all inboxes | Powered by JetHome®