From: Leon Romanovsky <leon@kernel.org>
To: Peilin Ye <yepeilin.cs@gmail.com>
Cc: rds-devel@oss.oracle.com, Arnd Bergmann <arnd@arndb.de>,
linux-rdma@vger.kernel.org,
Santosh Shilimkar <santosh.shilimkar@oracle.com>,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
Jakub Kicinski <kuba@kernel.org>,
linux-kernel-mentees@lists.linuxfoundation.org,
"David S. Miller" <davem@davemloft.net>,
Dan Carpenter <dan.carpenter@oracle.com>
Subject: Re: [Linux-kernel-mentees] [PATCH net] rds: Prevent kernel-infoleak in rds_notify_queue_get()
Date: Fri, 31 Jul 2020 07:53:01 +0300 [thread overview]
Message-ID: <20200731045301.GI75549@unreal> (raw)
In-Reply-To: <20200730192026.110246-1-yepeilin.cs@gmail.com>
On Thu, Jul 30, 2020 at 03:20:26PM -0400, Peilin Ye wrote:
> rds_notify_queue_get() is potentially copying uninitialized kernel stack
> memory to userspace since the compiler may leave a 4-byte hole at the end
> of `cmsg`.
>
> In 2016 we tried to fix this issue by doing `= { 0 };` on `cmsg`, which
> unfortunately does not always initialize that 4-byte hole. Fix it by using
> memset() instead.
Of course, this is the difference between "{ 0 }" and "{}" initializations.
>
> Cc: stable@vger.kernel.org
> Fixes: f037590fff30 ("rds: fix a leak of kernel memory")
> Fixes: bdbe6fbc6a2f ("RDS: recv.c")
> Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
> ---
> Note: the "real" copy_to_user() happens in put_cmsg(), where
> `cmlen - sizeof(*cm)` equals to `sizeof(cmsg)`.
>
> Reference: https://lwn.net/Articles/417989/
>
> $ pahole -C "rds_rdma_notify" net/rds/recv.o
> struct rds_rdma_notify {
> __u64 user_token; /* 0 8 */
> __s32 status; /* 8 4 */
>
> /* size: 16, cachelines: 1, members: 2 */
> /* padding: 4 */
> /* last cacheline: 16 bytes */
> };
>
> net/rds/recv.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/net/rds/recv.c b/net/rds/recv.c
> index c8404971d5ab..aba4afe4dfed 100644
> --- a/net/rds/recv.c
> +++ b/net/rds/recv.c
> @@ -450,12 +450,13 @@ static int rds_still_queued(struct rds_sock *rs, struct rds_incoming *inc,
> int rds_notify_queue_get(struct rds_sock *rs, struct msghdr *msghdr)
> {
> struct rds_notifier *notifier;
> - struct rds_rdma_notify cmsg = { 0 }; /* fill holes with zero */
> + struct rds_rdma_notify cmsg;
> unsigned int count = 0, max_messages = ~0U;
> unsigned long flags;
> LIST_HEAD(copy);
> int err = 0;
>
> + memset(&cmsg, 0, sizeof(cmsg)); /* fill holes with zero */
It works, but the right solution is to drop 0 from cmsg initialization
and write "struct rds_rdma_notify cmsg = {};" without any memset.
Thanks
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
WARNING: multiple messages have this Message-ID (diff)
From: Leon Romanovsky <leon@kernel.org>
To: Peilin Ye <yepeilin.cs@gmail.com>
Cc: Santosh Shilimkar <santosh.shilimkar@oracle.com>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Dan Carpenter <dan.carpenter@oracle.com>,
Arnd Bergmann <arnd@arndb.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-kernel-mentees@lists.linuxfoundation.org,
netdev@vger.kernel.org, linux-rdma@vger.kernel.org,
rds-devel@oss.oracle.com, linux-kernel@vger.kernel.org
Subject: Re: [Linux-kernel-mentees] [PATCH net] rds: Prevent kernel-infoleak in rds_notify_queue_get()
Date: Fri, 31 Jul 2020 07:53:01 +0300 [thread overview]
Message-ID: <20200731045301.GI75549@unreal> (raw)
In-Reply-To: <20200730192026.110246-1-yepeilin.cs@gmail.com>
On Thu, Jul 30, 2020 at 03:20:26PM -0400, Peilin Ye wrote:
> rds_notify_queue_get() is potentially copying uninitialized kernel stack
> memory to userspace since the compiler may leave a 4-byte hole at the end
> of `cmsg`.
>
> In 2016 we tried to fix this issue by doing `= { 0 };` on `cmsg`, which
> unfortunately does not always initialize that 4-byte hole. Fix it by using
> memset() instead.
Of course, this is the difference between "{ 0 }" and "{}" initializations.
>
> Cc: stable@vger.kernel.org
> Fixes: f037590fff30 ("rds: fix a leak of kernel memory")
> Fixes: bdbe6fbc6a2f ("RDS: recv.c")
> Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
> ---
> Note: the "real" copy_to_user() happens in put_cmsg(), where
> `cmlen - sizeof(*cm)` equals to `sizeof(cmsg)`.
>
> Reference: https://lwn.net/Articles/417989/
>
> $ pahole -C "rds_rdma_notify" net/rds/recv.o
> struct rds_rdma_notify {
> __u64 user_token; /* 0 8 */
> __s32 status; /* 8 4 */
>
> /* size: 16, cachelines: 1, members: 2 */
> /* padding: 4 */
> /* last cacheline: 16 bytes */
> };
>
> net/rds/recv.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/net/rds/recv.c b/net/rds/recv.c
> index c8404971d5ab..aba4afe4dfed 100644
> --- a/net/rds/recv.c
> +++ b/net/rds/recv.c
> @@ -450,12 +450,13 @@ static int rds_still_queued(struct rds_sock *rs, struct rds_incoming *inc,
> int rds_notify_queue_get(struct rds_sock *rs, struct msghdr *msghdr)
> {
> struct rds_notifier *notifier;
> - struct rds_rdma_notify cmsg = { 0 }; /* fill holes with zero */
> + struct rds_rdma_notify cmsg;
> unsigned int count = 0, max_messages = ~0U;
> unsigned long flags;
> LIST_HEAD(copy);
> int err = 0;
>
> + memset(&cmsg, 0, sizeof(cmsg)); /* fill holes with zero */
It works, but the right solution is to drop 0 from cmsg initialization
and write "struct rds_rdma_notify cmsg = {};" without any memset.
Thanks
next prev parent reply other threads:[~2020-07-31 4:53 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-30 19:20 [Linux-kernel-mentees] [PATCH net] rds: Prevent kernel-infoleak in rds_notify_queue_get() Peilin Ye
2020-07-30 19:20 ` Peilin Ye
2020-07-30 19:29 ` santosh.shilimkar
2020-07-30 19:29 ` santosh.shilimkar
2020-07-31 4:53 ` Leon Romanovsky [this message]
2020-07-31 4:53 ` Leon Romanovsky
2020-07-31 5:33 ` Greg Kroah-Hartman
2020-07-31 5:33 ` Greg Kroah-Hartman
2020-07-31 5:33 ` Greg Kroah-Hartman
2020-07-31 5:33 ` Greg Kroah-Hartman
2020-07-31 6:29 ` Andy Shevchenko
2020-07-31 7:00 ` Leon Romanovsky
2020-07-31 7:00 ` Leon Romanovsky
2020-07-31 7:05 ` Andy Shevchenko
2020-07-31 7:05 ` Andy Shevchenko
2020-07-31 14:04 ` Jason Gunthorpe
2020-07-31 14:04 ` Jason Gunthorpe
2020-07-31 14:21 ` Greg Kroah-Hartman
2020-07-31 14:21 ` Greg Kroah-Hartman
2020-07-31 14:36 ` Jason Gunthorpe
2020-07-31 14:36 ` Jason Gunthorpe
2020-07-31 17:19 ` Greg Kroah-Hartman
2020-07-31 17:19 ` Greg Kroah-Hartman
2020-07-31 18:27 ` Jason Gunthorpe
2020-07-31 18:27 ` Jason Gunthorpe
2020-08-01 8:00 ` Dan Carpenter
2020-08-01 8:00 ` Dan Carpenter
2020-08-01 14:40 ` Jason Gunthorpe
2020-08-01 14:40 ` Jason Gunthorpe
2020-08-03 9:34 ` Dan Carpenter
2020-08-03 9:34 ` Dan Carpenter
2020-08-01 5:38 ` Leon Romanovsky
2020-08-01 5:38 ` Leon Romanovsky
2020-08-02 22:10 ` Jason Gunthorpe
2020-08-02 22:10 ` Jason Gunthorpe
2020-08-02 22:23 ` Joe Perches
2020-08-02 22:23 ` Joe Perches
2020-08-02 22:28 ` Jason Gunthorpe
2020-08-02 22:28 ` Jason Gunthorpe
2020-08-02 22:45 ` Joe Perches
2020-08-02 22:45 ` Joe Perches
2020-08-03 4:58 ` Leon Romanovsky
2020-08-03 4:58 ` Leon Romanovsky
2020-08-03 23:06 ` Jason Gunthorpe
2020-08-03 23:06 ` Jason Gunthorpe
2020-08-08 22:57 ` Jack Leadford
2020-08-08 22:57 ` Jack Leadford
2020-08-09 7:04 ` Leon Romanovsky
2020-08-09 7:04 ` Leon Romanovsky
2020-08-14 17:07 ` Jason Gunthorpe
2020-08-14 17:07 ` Jason Gunthorpe
2020-07-31 6:31 ` Andy Shevchenko
2020-07-31 9:59 ` Dan Carpenter
2020-07-31 9:59 ` Dan Carpenter
2020-07-31 11:14 ` Håkon Bugge
2020-07-31 11:14 ` Håkon Bugge
2020-07-31 11:59 ` Greg Kroah-Hartman
2020-07-31 11:59 ` Greg Kroah-Hartman
2020-07-31 12:03 ` Håkon Bugge
2020-07-31 12:03 ` Håkon Bugge
2020-07-31 23:54 ` David Miller
2020-07-31 23:54 ` David Miller
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=20200731045301.GI75549@unreal \
--to=leon@kernel.org \
--cc=arnd@arndb.de \
--cc=dan.carpenter@oracle.com \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=linux-kernel-mentees@lists.linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=rds-devel@oss.oracle.com \
--cc=santosh.shilimkar@oracle.com \
--cc=yepeilin.cs@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.