Skip to contentSkip to conversation

bio_uncopy_user mem leak

PATCH In review Kurt Garloff 4 participants 4 messages Aug 17, 2004 – Aug 19, 2004 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bio_uncopy_user mem leak

Hi Andrew,

When using bounce buffers for SG_IO commands with unaligned buffers in blk_rq_map_user(), we should free the pages from blk_rq_unmap_user() which calls bio_uncopy_user() for the non-BIO_USER_MAPPED case. That function failed to free the pages for write requests.

So we leaked pages and you machine would go OOM. Rebooting helped ;-)

This bug was triggered by writing audio CDs (but not on data CDs), as the audio frames are not aligned well (2352 bytes), so the user pages don't just get mapped.

Bug was reported by Mathias Homan and debugged by Chris Mason + me. (Jens is away.)

 bio.c |   21 +++++++++------------
 1 files changed, 9 insertions(+), 12 deletions(-)
fs/bio.c renamed from fs/bio.c.orig +9 -12
@@ -388,20 +388,17 @@ int bio_uncopy_user(struct bio *bio)
 	struct bio_vec *bvec;
 	int i, ret = 0;
 
-	if (bio_data_dir(bio) == READ) {
-		char *uaddr = bio->bi_private;
-
-		__bio_for_each_segment(bvec, bio, i, 0) {
-			char *addr = page_address(bvec->bv_page);
-
-			if (!ret && copy_to_user(uaddr, addr, bvec->bv_len))
-				ret = -EFAULT;
+	char *uaddr = bio->bi_private;
+	
+	__bio_for_each_segment(bvec, bio, i, 0) {
+		char *addr = page_address(bvec->bv_page);
+		if (bio_data_dir(bio) == READ && !ret && 
+		    copy_to_user(uaddr, addr, bvec->bv_len))
+			ret = -EFAULT;
 
-			__free_page(bvec->bv_page);
-			uaddr += bvec->bv_len;
-		}
+		__free_page(bvec->bv_page);
+		uaddr += bvec->bv_len;
 	}
-
 	bio_put(bio);
 	return ret;
 }
Signature · 1 line
Kurt Garloff, Director SUSE Labs, Novell
#1 lore raw

On Tuesday 17 August 2004 11:59, Kurt Garloff wrote:

Posted a patch for a memory leak. I have no idea whats got into me, but I just applied this one to see if it has anything to do with my "possible dcache problem".

FWIW, I had to do it by hand even though it looked dead on for 2.6.8-rc4/fs/bio.c

No errors when recompiling.

Signature · 8 lines
Cheers, Gene
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
99.24% setiathome rank, not too shabby for a WV hillbilly
Yahoo.com attorneys please note, additions to this message
by Gene Heskett are:
Copyright 2004 by Maurice Eugene Heskett, all rights reserved.
#2 lore raw
In reply to Kurt Garloff
Quoted 9 lines · Kurt Garloff

When using bounce buffers for SG_IO commands with unaligned buffers in blk_rq_map_user(), we should free the pages from blk_rq_unmap_user() which calls bio_uncopy_user() for the non-BIO_USER_MAPPED case. That function failed to free the pages for write requests.

So we leaked pages and you machine would go OOM. Rebooting helped ;-)

Eureka. Thanks.

This really should trigger a 2.6.8.2. We'll see.

#3 lore raw
In reply to Kurt Garloff

Hi,

Quoted 3 lines

This bug was triggered by writing audio CDs (but not on data CDs), as the audio frames are not aligned well (2352 bytes), so the user pages don't just get mapped.

This patch has been reported by a few people as fixing the leak problem, but the produced audio CDs are corrupt.
(I didn't try it myself, already trashed 2 CDs ;-))

see http://kerneltrap.org/node/view/3659 for example

Thanks for your work,

Signature · 1 line
Colin