mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kurt Garloff <garloff@suse.de>
To: Andrew Morton <akpm@osdl.org>
Cc: Linux kernel list <linux-kernel@vger.kernel.org>
Subject: [PATCH] bio_uncopy_user mem leak
Date: Tue, 17 Aug 2004 17:59:18 +0200	[thread overview]
Message-ID: <20040817155918.GA5312@tpkurt.garloff.de> (raw)

[-- Attachment #1: Type: text/plain, Size: 1717 bytes --]

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.)

Signed-off-by: Kurt Garloff <garloff@suse.de>

 bio.c |   21 +++++++++------------
 1 files changed, 9 insertions(+), 12 deletions(-)

--- linux-2.6.8.x86/fs/bio.c.orig	2004-08-14 07:37:15.000000000 +0200
+++ linux-2.6.8.x86/fs/bio.c	2004-08-17 17:41:52.022012902 +0200
@@ -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;
 }

-- 
Kurt Garloff, Director SUSE Labs, Novell

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

             reply	other threads:[~2004-08-17 16:00 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-17 15:59 Kurt Garloff [this message]
2004-08-17 21:08 ` Gene Heskett
2004-08-17 22:50 ` Andrew Morton
2004-08-19  7:16 ` Colin Leroy
2004-08-19  9:59 Greg Afinogenov
2004-08-19 11:07 ` Con Kolivas
2004-08-19 13:51   ` Chris Mason
2004-08-19 19:55     ` Kurt Garloff
2004-08-20  3:19       ` Con Kolivas
2004-08-20  6:31         ` Andrew Morton
2004-08-20 12:54           ` Kurt Garloff
2004-08-20 20:28           ` sandr8
2004-08-20  7:15         ` Greg Afinogenov
2004-08-20 12:46         ` Kurt Garloff

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040817155918.GA5312@tpkurt.garloff.de \
    --to=garloff@suse.de \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®