Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp960840ybg; Wed, 29 Jul 2020 02:08:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUCFZ/sn7TrhM/Qez+mTD/3jmZTiqNigkZNbux0NGt2SMXRnD3DBs1mKNpq4WgihByoRbY X-Received: by 2002:a05:6402:1ca8:: with SMTP id cz8mr29239861edb.55.1596013703392; Wed, 29 Jul 2020 02:08:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596013703; cv=none; d=google.com; s=arc-20160816; b=eCMSIeu5GnX8TVjMkffnGwQe00+dFtN6lNHrGI7Me9ejpqmvX8tVT+gr8Y12nuNJ3k FKlUBTiODjjxPCNWcRrb+C3jbnxy3HaendCbNEV6MBPu/jlW6j8avB7NS5k6FI9E/xPl pxDYvNDf9IR0qALsu0igcS35RWa6+O/3uBUeAKgGv5biLEq2XKe2/odgYdVhCfBOH9d0 eDVdEWd1XSRm6orGvRhDL7FA6CMJwV11y4VbyLBROImS1v3SvE3IqhbwG8N6WvByI1mH Bqf+Rw+0qKtJRg2rT1sZ5Ygpvkbxq0WogcCb6nubCXjifWusiobmDZqmiQbpRlj2XkDo 3qNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:subject:autocrypt:from:references:cc:to:reply-to; bh=0ixb1jJgq4PcU3Usk6ZmktN5ND8M3VvBo7EWZku4aSU=; b=H25AWs1Zw0uVf0mi7ETeqqAjcmBwPTTxMgCXsgbrKdTzuYHrwKNWP7IG1+RnrFNTRW EQjT2p3+U2i4SncJmsOnub0PSpB5+fgbufkVyIcZiwh/n27X+0RtGnIENDxSCMgZyYDh 6PHLU2kO3KdRRXDsMa1jyL2igwSgkg1JyGaoxDADIdx+ynyv0Z76B2BN6ml4b27h+5Ty 6wxsf0leiZAphY+9SmUR9JOLr19qvh5xmcNCmsVroH7N6yaf9m0sOHuT0mEJLlc13Z4x Mi1FKBCyTQ7HiYHcT3wVNya6veEwFquf92KD0Up2GJy9N4/LV9HOpiH89e/VtWVefFfH VdJg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c19si689108ejr.522.2020.07.29.02.08.01; Wed, 29 Jul 2020 02:08:23 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728008AbgG2JH0 (ORCPT + 99 others); Wed, 29 Jul 2020 05:07:26 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:37669 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726336AbgG2JH0 (ORCPT ); Wed, 29 Jul 2020 05:07:26 -0400 Received: by mail-lj1-f193.google.com with SMTP id q6so24209786ljp.4; Wed, 29 Jul 2020 02:07:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:to:cc:references:from:autocrypt:subject :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=0ixb1jJgq4PcU3Usk6ZmktN5ND8M3VvBo7EWZku4aSU=; b=Apdf3v2D68FwynV5cJZeswSoxaqucrbGWikP0iFCGPdc/1vz5UQeFT0fY8FqtT78Cs 3QGyEiRJioMXUUJOhtQ/3ksNQt6w9EGqBJ7+nxDcT7Mwx7ZVO2DIrVZ+EC24HT34tApz sSFuiGeHBCqB1IqjvDtS28u7DXBXa9nPOonIToLOeu6lq4wC462bVmLV6iyeeIpbDYmK ojbES/F03W2LHxmbKAlAXl+UHvVIo+1hJuVO2hkBCrPUVxU3HgVNNGxr0kEXoxbk69zF mFnjjdOngyM94FjGI9TtAVSNFEKdX9fY65oZV9XGa/Js2PPQM79iqNWcrhPhVSNltAko PTZg== X-Gm-Message-State: AOAM532Hj6HaDCUicgHMWAEYc7ctu/T9/hUQAojtjFBFlMtKI5d0fRgm yorSy8/WkzaiTX+SdGhFuFqam03hW+0= X-Received: by 2002:a2e:7601:: with SMTP id r1mr15299166ljc.111.1596013642633; Wed, 29 Jul 2020 02:07:22 -0700 (PDT) Received: from [10.68.32.147] (broadband-37-110-38-130.ip.moscow.rt.ru. [37.110.38.130]) by smtp.gmail.com with ESMTPSA id s2sm272584ljg.84.2020.07.29.02.07.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Jul 2020 02:07:22 -0700 (PDT) Reply-To: efremov@linux.com To: Peilin Ye , Jens Axboe Cc: Arnd Bergmann , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, Dan Carpenter References: <20200728141946.426245-1-yepeilin.cs@gmail.com> From: Denis Efremov Autocrypt: addr=efremov@linux.com; keydata= mQINBFsJUXwBEADDnzbOGE/X5ZdHqpK/kNmR7AY39b/rR+2Wm/VbQHV+jpGk8ZL07iOWnVe1 ZInSp3Ze+scB4ZK+y48z0YDvKUU3L85Nb31UASB2bgWIV+8tmW4kV8a2PosqIc4wp4/Qa2A/ Ip6q+bWurxOOjyJkfzt51p6Th4FTUsuoxINKRMjHrs/0y5oEc7Wt/1qk2ljmnSocg3fMxo8+ y6IxmXt5tYvt+FfBqx/1XwXuOSd0WOku+/jscYmBPwyrLdk/pMSnnld6a2Fp1zxWIKz+4VJm QEIlCTe5SO3h5sozpXeWS916VwwCuf8oov6706yC4MlmA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gzXaZ2+QJjp44HSyzxgONmHAroFcqCFUlfAqUDO T30gV5bQ8BHqvfWyEhJT+CS3JJyP8BmmSgPa0Adlp6Do+pRsOO1YNNO78SYABhMi3fEa7X37 WxL31TrNCPnIauTgZtf/KCFQJpKaakC3ffEkPhyTjEl7oOE9xccNjccZraadi+2uHV0ULA1m ycHhb817A03n1I00QwLf2wOkckdqTqRbFFI/ik69hF9hemK/BmAHpShI+z1JsYT9cSs8D7wb aF/jQVy4URensgAPkgXsRiboqOj/rTz9F5mpd/gPU/IOUPFEMoo4TInt/+dEVECHioU3RRrW EahrGMfRngbdp/mKs9aBR56ECMfFFUPyI3VJsNbgpcIJjV/0N+JdJKQpJ/4uQ2zNm0wH/RU8 CRJvEwtKemX6fp/zLI36Gvz8zJIjSBIEqCb7vdgvWarksrhmi6/Jay5zRZ03+k6YwiqgX8t7 ANwvYa1h1dQ36OiTqm1cIxRCGl4wrypOVGx3OjCar7sBLD+NkwO4RaqFvdv0xuuy4x01VnOF Subject: Re: [Linux-kernel-mentees] [PATCH] block/floppy: Prevent kernel-infoleak in raw_cmd_copyout() Message-ID: <40446b2c-3885-1b30-c0b3-5f544a96ed78@linux.com> Date: Wed, 29 Jul 2020 12:07:20 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200728141946.426245-1-yepeilin.cs@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 7/28/20 5:19 PM, Peilin Ye wrote: > raw_cmd_copyout() is potentially copying uninitialized kernel stack memory > since it is initializing `cmd` by assignment, which may cause the compiler > to leave uninitialized holes in this structure. Fix it by using memcpy() > instead. > > Cc: stable@vger.kernel.org > Fixes: 2145e15e0557 ("floppy: don't write kernel-only members to FDRAWCMD ioctl output") > Suggested-by: Dan Carpenter > Suggested-by: Arnd Bergmann > Signed-off-by: Peilin Ye Reviewed-by: Denis Efremov ptr comes from raw_cmd_copyin and it should be ok to use memcpy. Jens, could you please take this one to your 5.9 branch? > --- > $ pahole -C "floppy_raw_cmd" drivers/block/floppy.o > struct floppy_raw_cmd { > unsigned int flags; /* 0 4 */ > > /* XXX 4 bytes hole, try to pack */ > > void * data; /* 8 8 */ > char * kernel_data; /* 16 8 */ > struct floppy_raw_cmd * next; /* 24 8 */ > long int length; /* 32 8 */ > long int phys_length; /* 40 8 */ > int buffer_length; /* 48 4 */ > unsigned char rate; /* 52 1 */ > unsigned char cmd_count; /* 53 1 */ > union { > struct { > unsigned char cmd[16]; /* 54 16 */ > /* --- cacheline 1 boundary (64 bytes) was 6 bytes ago --- */ > unsigned char reply_count; /* 70 1 */ > unsigned char reply[16]; /* 71 16 */ > }; /* 54 33 */ > unsigned char fullcmd[33]; /* 54 33 */ > }; /* 54 33 */ > > /* XXX 1 byte hole, try to pack */ > > /* --- cacheline 1 boundary (64 bytes) was 24 bytes ago --- */ > int track; /* 88 4 */ > int resultcode; /* 92 4 */ > int reserved1; /* 96 4 */ > int reserved2; /* 100 4 */ > > /* size: 104, cachelines: 2, members: 14 */ > /* sum members: 99, holes: 2, sum holes: 5 */ > /* last cacheline: 40 bytes */ > }; > It would be nice to add lkml links with discussion on the issue or https://www.nccgroup.com/us/about-us/newsroom-and-events/blog/2019/october/padding-the-struct-how-a-compiler-optimization-can-disclose-stack-memory/ in addition to pahole output. > drivers/block/floppy.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c > index 09079aee8dc4..b8ea98f7a9cb 100644 > --- a/drivers/block/floppy.c > +++ b/drivers/block/floppy.c > @@ -3126,7 +3126,9 @@ static int raw_cmd_copyout(int cmd, void __user *param, > int ret; > > while (ptr) { > - struct floppy_raw_cmd cmd = *ptr; > + struct floppy_raw_cmd cmd; > + > + memcpy(&cmd, ptr, sizeof(cmd))> cmd.next = NULL; > cmd.kernel_data = NULL; > ret = copy_to_user(param, &cmd, sizeof(cmd)); > Thanks, Denis