From patchwork Thu Mar 21 01:15:30 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: fanchaoting X-Patchwork-Id: 2310781 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id E8DE5DF24C for ; Thu, 21 Mar 2013 01:15:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751348Ab3CUBPI (ORCPT ); Wed, 20 Mar 2013 21:15:08 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:19988 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751346Ab3CUBPH convert rfc822-to-8bit (ORCPT ); Wed, 20 Mar 2013 21:15:07 -0400 X-IronPort-AV: E=Sophos;i="4.84,882,1355068800"; d="scan'208";a="6913540" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 21 Mar 2013 09:12:35 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id r2L1F3Tb007292; Thu, 21 Mar 2013 09:15:03 +0800 Received: from [127.0.0.1] ([10.167.233.142]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2013032109133235-1029406 ; Thu, 21 Mar 2013 09:13:32 +0800 Message-ID: <514A5F32.2020603@cn.fujitsu.com> Date: Thu, 21 Mar 2013 09:15:30 +0800 From: fanchaoting User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: "Myklebust, Trond" CC: "linux-nfs@vger.kernel.org" Subject: Re: [PATCH] pnfs-block: removing DM device maybe cause oops when call dev_remove References: <51496CC5.7040400@cn.fujitsu.com> <1363807637.4790.63.camel@leira.trondhjem.org> In-Reply-To: <1363807637.4790.63.camel@leira.trondhjem.org> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/03/21 09:13:32, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/03/21 09:13:37, Serialize complete at 2013/03/21 09:13:37 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Myklebust, Trond ??: > On Wed, 2013-03-20 at 16:01 +0800, fanchaoting wrote: >> when pnfs block using device mapper,if umounting later,it maybe >> cause oops. we apply "1 + sizeof(bl_umount_request)" memory for >> msg->data, the memory maybe overflow when we do "memcpy(&dataptr >> [sizeof(bl_msg)], &bl_umount_request, sizeof(bl_umount_request))", >> because the size of bl_msg is more than 1 byte. >> >> Signed-off-by: fanchaoting >> >> --- >> fs/nfs/blocklayout/blocklayoutdm.c | 2 +- >> 1 files changed, 1 insertions(+), 1 deletions(-) >> >> diff --git a/fs/nfs/blocklayout/blocklayoutdm.c b/fs/nfs/blocklayout/blocklayoutdm.c >> index 737d839..8df9afa 100644 >> --- a/fs/nfs/blocklayout/blocklayoutdm.c >> +++ b/fs/nfs/blocklayout/blocklayoutdm.c >> @@ -55,7 +55,7 @@ static void dev_remove(struct net *net, dev_t dev) >> >> bl_pipe_msg.bl_wq = &nn->bl_wq; >> memset(msg, 0, sizeof(*msg)); >> - msg->data = kzalloc(1 + sizeof(bl_umount_request), GFP_NOFS); >> + msg->data = kzalloc(sizeof(bl_msg) + sizeof(bl_umount_request), GFP_NOFS); >> if (!msg->data) >> goto out; >> > > Why not just move the calculation of msg->len, and then use msg->len in > the above allocation? > yes, you are right, thanks for reviewing, here is the change patch. when pnfs block using device mapper,if umounting later,it maybe cause oops. we apply "1 + sizeof(bl_umount_request)" memory for msg->data, the memory maybe overflow when we do "memcpy(&dataptr [sizeof(bl_msg)], &bl_umount_request, sizeof(bl_umount_request))", because the size of bl_msg is more than 1 byte. Signed-off-by: fanchaoting Reviewed-by: Trond Myklebust --- fs/nfs/blocklayout/blocklayoutdm.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/nfs/blocklayout/blocklayoutdm.c b/fs/nfs/blocklayout/blocklayoutdm.c index 737d839..6fc7b5c 100644 --- a/fs/nfs/blocklayout/blocklayoutdm.c +++ b/fs/nfs/blocklayout/blocklayoutdm.c @@ -55,7 +55,8 @@ static void dev_remove(struct net *net, dev_t dev) bl_pipe_msg.bl_wq = &nn->bl_wq; memset(msg, 0, sizeof(*msg)); - msg->data = kzalloc(1 + sizeof(bl_umount_request), GFP_NOFS); + msg->len = sizeof(bl_msg) + bl_msg.totallen; + msg->data = kzalloc(msg->len, GFP_NOFS); if (!msg->data) goto out; @@ -66,7 +67,6 @@ static void dev_remove(struct net *net, dev_t dev) memcpy(msg->data, &bl_msg, sizeof(bl_msg)); dataptr = (uint8_t *) msg->data; memcpy(&dataptr[sizeof(bl_msg)], &bl_umount_request, sizeof(bl_umount_request)); - msg->len = sizeof(bl_msg) + bl_msg.totallen; add_wait_queue(&nn->bl_wq, &wq); if (rpc_queue_upcall(nn->bl_device_pipe, msg) < 0) {