From patchwork Thu Sep 15 23:16:45 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 114869 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id BA36AB70D1 for ; Fri, 16 Sep 2011 09:16:53 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935343Ab1IOXQv (ORCPT ); Thu, 15 Sep 2011 19:16:51 -0400 Received: from e6.ny.us.ibm.com ([32.97.182.146]:52293 "EHLO e6.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932690Ab1IOXQv (ORCPT ); Thu, 15 Sep 2011 19:16:51 -0400 Received: from d01relay01.pok.ibm.com (d01relay01.pok.ibm.com [9.56.227.233]) by e6.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id p8FMqdrE005095; Thu, 15 Sep 2011 18:52:39 -0400 Received: from d01av02.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216]) by d01relay01.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p8FNGnGD186822; Thu, 15 Sep 2011 19:16:49 -0400 Received: from d01av02.pok.ibm.com (loopback [127.0.0.1]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p8FNGl5c011056; Thu, 15 Sep 2011 20:16:48 -0300 Received: from tux1.beaverton.ibm.com ([9.47.67.50]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p8FNGkM7011017; Thu, 15 Sep 2011 20:16:46 -0300 Received: by tux1.beaverton.ibm.com (Postfix, from userid 501) id D7AB413E88F; Thu, 15 Sep 2011 16:16:45 -0700 (PDT) Date: Thu, 15 Sep 2011 16:16:45 -0700 From: "Darrick J. Wong" To: "Theodore Ts'o" Cc: linux-kernel , linux-ext4 Subject: [PATCH] ext4: Prevent stack overrun in ext4_file_open when recording last known mountpoint Message-ID: <20110915231645.GE12086@tux1.beaverton.ibm.com> Reply-To: djwong@us.ibm.com MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.17+20080114 (2008-01-14) Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org In ext4_file_open, the filesystem records the mountpoint of the first file that is opened after mounting the filesystem. It does this by allocating a 64-byte stack buffer, calling d_path() to grab the mount point through which this file was accessed, and then memcpy()ing 64 bytes into the superblock's s_last_mounted field, starting from the return value of d_path(), which is stored as "cp". However, if cp > buf (which it frequently is since path components are prepended starting at the end of buf) then we can end up copying stack data into the superblock. Writing stack variables into the superblock doesn't sound like a great idea, so use strncpy instead. Signed-off-by: Darrick J. Wong --- fs/ext4/file.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" 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/ext4/file.c b/fs/ext4/file.c index e4095e9..67223e0 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -181,8 +181,8 @@ static int ext4_file_open(struct inode * inode, struct file * filp) path.dentry = mnt->mnt_root; cp = d_path(&path, buf, sizeof(buf)); if (!IS_ERR(cp)) { - memcpy(sbi->s_es->s_last_mounted, cp, - sizeof(sbi->s_es->s_last_mounted)); + strncpy(sbi->s_es->s_last_mounted, cp, + sizeof(sbi->s_es->s_last_mounted)); ext4_mark_super_dirty(sb); } }