Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp2428936ybg; Thu, 30 Jul 2020 21:53:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyEM8h7f6CymHKk7gJE0QCG7avhI5Hayu3Km7V1BPuvd0hQP26Sav3NhEfiNMfb00qv9Sr3 X-Received: by 2002:a17:906:7783:: with SMTP id s3mr2289940ejm.6.1596171229158; Thu, 30 Jul 2020 21:53:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596171229; cv=none; d=google.com; s=arc-20160816; b=XhJK5BGWO9AvAERxKAjl7mOY8lPH4kVleEUZgrOQVGVtY4dvsXwA7AG3VJZEMGY2mw flsXUQ2Qg9fBzpj++pT0VjQbwNf3x69OOJrgYbjO3NcqCmM9eg9pJbyBTprTDqpXW7SW 95D0H8zUm2NgRKOKVSIU41kWrf06OcCNrpxFs0PvKYbaJzdzHdqPau3ZFQ49AJ08cELX rh4UNRzIQgpGli8by4YQfdnisHhX3UetlTQx6sO1ojZVJj3lYyPDJLU9uG9KcsqW4MKG Ku8sez/hc/LawifOPowTZqhBljyGziSuc2mtZCwp9pbBA1tOJzmWZBILMYF/Nmf9OjMQ V9Zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=6td1nzaROVhTe2LPpNsqbdY6PZwW5fn0rmvabpa0qV4=; b=sXIclbwE88jB5BvDDrGIahosw5tPnq0ZxhdQS/I0vNLYWERwCTp8riq+8fTkIlVv7j IBJrWtaw3Pr4pImiDO5nbs4CS9QAgk/75AzYwsuY4mwNDfUq5yYN5OQllwmrjpSSlGdQ Mo5MLTac4sry2MwqmxRQQW40jH6T4n4UQ60byzHJ1LDlTUumXmP/tfZAhUJgrOSRqCh4 ZzBZVsIP5Wh4JG6yX/eAI/W5Rthkh4LQQirJUZzJI8j5B7kJTeGz+7HsAG1885IUbuAz 9BMCtVpX6B/RkmqFXRnk3DBX4OVi/PsVePHsrXQGVlJJyx1/RPqZRj2u94ZOqQQRyQ0c tPnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ugZ+u62G; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h27si4837736ejd.184.2020.07.30.21.53.22; Thu, 30 Jul 2020 21:53:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ugZ+u62G; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729545AbgGaExH (ORCPT + 99 others); Fri, 31 Jul 2020 00:53:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:60936 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725800AbgGaExG (ORCPT ); Fri, 31 Jul 2020 00:53:06 -0400 Received: from localhost (unknown [213.57.247.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 50CE12074B; Fri, 31 Jul 2020 04:53:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596171186; bh=MnEbR4t/xoxAN93gD+qE5jCDyQ4vcBjhtQp8diZ/N88=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ugZ+u62GbxspOh76EELUql3biENANGq3nTvcDrY1aGLphdm1mxDObpR/WAHU3Upvn I6lfZeT+cGvAyIdNSrO/BfjIlqiTUE6aaA+CVw0L9tF5MEzpHH9faVIlaS8keDBqB8 hn6iSlGtBHbLSPJg0Yb5zkpCpXC//r+57UaXAD0s= Date: Fri, 31 Jul 2020 07:53:01 +0300 From: Leon Romanovsky To: Peilin Ye Cc: Santosh Shilimkar , "David S. Miller" , Jakub Kicinski , Dan Carpenter , Arnd Bergmann , Greg Kroah-Hartman , 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() Message-ID: <20200731045301.GI75549@unreal> References: <20200730192026.110246-1-yepeilin.cs@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200730192026.110246-1-yepeilin.cs@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > Signed-off-by: Peilin Ye > --- > 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