From: Dave Kleikamp Subject: vfs: Don't call attach_nobh_buffers() with an empty list Date: Fri, 06 Feb 2009 14:59:26 -0600 Message-ID: <1233953966.7020.5.camel@norville.austin.ibm.com> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit Cc: Andrew Morton , linux-fsdevel , Bill Pemberton , Dmitri Monakhov To: Linus Torvalds Return-path: Received: from e2.ny.us.ibm.com ([32.97.182.142]:43634 "EHLO e2.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752698AbZBFU7a (ORCPT ); Fri, 6 Feb 2009 15:59:30 -0500 Received: from d01relay02.pok.ibm.com (d01relay02.pok.ibm.com [9.56.227.234]) by e2.ny.us.ibm.com (8.13.1/8.13.1) with ESMTP id n16KvZ53014663 for ; Fri, 6 Feb 2009 15:57:35 -0500 Received: from d01av03.pok.ibm.com (d01av03.pok.ibm.com [9.56.224.217]) by d01relay02.pok.ibm.com (8.13.8/8.13.8/NCO v9.1) with ESMTP id n16KxTG4183616 for ; Fri, 6 Feb 2009 15:59:29 -0500 Received: from d01av03.pok.ibm.com (loopback [127.0.0.1]) by d01av03.pok.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id n16KxSTA005902 for ; Fri, 6 Feb 2009 15:59:29 -0500 Sender: linux-fsdevel-owner@vger.kernel.org List-ID: vfs: Don't call attach_nobh_buffers() with an empty list This is a modification of a patch by Bill Pemberton nobh_write_end() could call attach_nobh_buffers() with head == NULL. This would result in a trap when attach_nobh_buffers() attempted to access bh->b_this_page. This can be illustrated by running the writev01 testcase from LTP on jfs. This error was introduced by commit 5b41e74a "vfs: fix data leak in nobh_write_end()". That patch did not take into account that if PageMappedToDisk() is true upon entry to nobh_write_begin(), then no buffers will be allocated for the page. In that case, we won't have to worry about a failed write leaving unitialized data in the page. Of course, head != NULL implies !page_has_buffers(page), so no need to test both. Signed-off-by: Dave Kleikamp Cc: Bill Pemberton Cc: Dmitri Monakhov diff --git a/fs/buffer.c b/fs/buffer.c index b58208f..665d446 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -2688,7 +2688,7 @@ int nobh_write_end(struct file *file, struct address_space *mapping, struct buffer_head *bh; BUG_ON(fsdata != NULL && page_has_buffers(page)); - if (unlikely(copied < len) && !page_has_buffers(page)) + if (unlikely(copied < len) && head) attach_nobh_buffers(page, head); if (page_has_buffers(page)) return generic_write_end(file, mapping, pos, len, -- David Kleikamp IBM Linux Technology Center