From patchwork Sat Nov 17 18:37:45 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Whitney X-Patchwork-Id: 199868 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 8AC1F2C0092 for ; Sun, 18 Nov 2012 05:37:52 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752031Ab2KQShu (ORCPT ); Sat, 17 Nov 2012 13:37:50 -0500 Received: from mail-qa0-f53.google.com ([209.85.216.53]:64082 "EHLO mail-qa0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751996Ab2KQShu (ORCPT ); Sat, 17 Nov 2012 13:37:50 -0500 Received: by mail-qa0-f53.google.com with SMTP id k31so2514228qat.19 for ; Sat, 17 Nov 2012 10:37:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=2TFHpvD8bOoKj69s39m+odXHmAgFF5QemQ2sSwlkG8s=; b=0HrJB7e45dbGqJa769Yr/q0up7RRKE2IVhNaTxe0+v5REXBmlPmUQz1nlKeM8Fe1e+ UsIj8AkzeEDXQbWHndW+9oFydUQpRfcnfBxs0OyHBzZ6YhZmGKYPZR5ilDq338RbaBbv P1ie4wPgblL7ABUJfAQqatOPLqemhD/5RTQgnfK3jgZ4A/OLGN49nCawytO+QJ5el5jl fLlxClEVKdUpgS/+kobhjb+KMTzEod7rnT5DfdxqAGsWn+wHrcuFLIpfABaBiOiKLEMO +2a7kB3Aqaag0FsgWbkAqpaLnatF4tm1vNns6fdD4KoKPFFa6bRktYdK5PqsNAVq7OFz kuGg== Received: by 10.49.71.71 with SMTP id s7mr8760269qeu.33.1353177469399; Sat, 17 Nov 2012 10:37:49 -0800 (PST) Received: from wallace (c-75-68-62-236.hsd1.nh.comcast.net. [75.68.62.236]) by mx.google.com with ESMTPS id h16sm3289829qae.8.2012.11.17.10.37.47 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 17 Nov 2012 10:37:48 -0800 (PST) Date: Sat, 17 Nov 2012 13:37:45 -0500 From: Eric Whitney To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu Subject: [PATCH] libext2fs: fix inode cache overruns Message-ID: <20121117183745.GA8489@wallace> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org An inode cache slot will be overrun if a caller to ext2fs_read_inode_full() or ext2fs_write_inode_full() attempts to read or write a full sized 156 byte inode when the target filesystem contains 128 byte inodes. Limit the copied inode to the smaller of the target filesystem's or the caller's requested inode size. Signed-off-by: Eric Whitney --- lib/ext2fs/inode.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/ext2fs/inode.c b/lib/ext2fs/inode.c index 0ea210e..e47d664 100644 --- a/lib/ext2fs/inode.c +++ b/lib/ext2fs/inode.c @@ -582,7 +582,8 @@ errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino, /* Check to see if it's in the inode cache */ for (i = 0; i < fs->icache->cache_size; i++) { if (fs->icache->cache[i].ino == ino) { - memcpy(inode, fs->icache->cache[i].inode, bufsize); + memcpy(inode, fs->icache->cache[i].inode, + (bufsize > length) ? length : bufsize); return 0; } } @@ -649,7 +650,7 @@ errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino, /* Update the inode cache bookkeeping */ fs->icache->cache_last = cache_slot; fs->icache->cache[cache_slot].ino = ino; - memcpy(inode, iptr, bufsize); + memcpy(inode, iptr, (bufsize > length) ? length : bufsize); return 0; } @@ -705,7 +706,7 @@ errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino, for (i=0; i < fs->icache->cache_size; i++) { if (fs->icache->cache[i].ino == ino) { memcpy(fs->icache->cache[i].inode, inode, - bufsize); + (bufsize > length) ? length : bufsize); break; } }