From: Pierre Etchemaite <petchema@concept-micro.com>
To: Jani Jaakkola <jjaakkol@cs.Helsinki.FI>
Cc: linux-kernel@vger.kernel.org
Subject: RE: [PATCH] fix a bug in ioctl(CDROMREADAUDIO) in cdrom.c in 2.2
Date: Thu, 15 Mar 2001 14:04:00 +0100 (CET) [thread overview]
Message-ID: <XFMail.20010315140400.petchema@concept-micro.com> (raw)
In-Reply-To: <Pine.LNX.4.30.0103141549340.733-100000@hallikari.cs.Helsinki.FI>
[-- Attachment #1: Type: text/plain, Size: 594 bytes --]
Le 14-Mar-2001, Jani Jaakkola écrivait :
>
> Using ioctl(CDROMREADAUDIO) with nframes argument being larger than 8 and
> not divisible by 8 causes kernel to read and return more audio data than
> was requested. This is bad since it clobbers up processes memory
> (I noticed this when my patched cdparanoia segfaulted).
Same thing for 2.4.2.
Is my allocation loop "over engineering", or just plain bad thing to do ?
Regards,
Pierre.
--
Linux blade.concept-micro.com 2.4.3-pre4 #1 Wed Mar 14 22:19:14 CET 2001 i686 unknown
2:04pm up 11:29, 4 users, load average: 2.66, 2.80, 2.26
[-- Attachment #2: myreadaudio.patch --]
[-- Type: application/octet-stream, Size: 1482 bytes --]
--- linux-2.4.2/drivers/cdrom/cdrom.c Wed Mar 14 22:15:52 2001
+++ linux/drivers/cdrom/cdrom.c Wed Mar 14 22:16:25 2001
@@ -1985,7 +1985,7 @@
}
case CDROMREADAUDIO: {
struct cdrom_read_audio ra;
- int lba;
+ int lba, frames;
IOCTL_IN(arg, struct cdrom_read_audio, ra);
@@ -2002,8 +2002,13 @@
if (lba < 0 || ra.nframes <= 0)
return -EINVAL;
- if ((cgc.buffer = (char *) kmalloc(CD_FRAMESIZE_RAW, GFP_KERNEL)) == NULL)
- return -ENOMEM;
+ frames = ra.nframes > 8 ? 8 : ra.nframes;
+
+ while((cgc.buffer = (char *) kmalloc(CD_FRAMESIZE_RAW * frames,
GFP_KERNEL)) == NULL) {
+ frames = frames >> 1;
+ if (!frames)
+ return -ENOMEM;
+ };
if (!access_ok(VERIFY_WRITE, ra.buf, ra.nframes*CD_FRAMESIZE_RAW)) {
kfree(cgc.buffer);
@@ -2011,12 +2016,16 @@
}
cgc.data_direction = CGC_DATA_READ;
while (ra.nframes > 0) {
- ret = cdrom_read_block(cdi, &cgc, lba, 1, 1, CD_FRAMESIZE_RAW);
- if (ret) break;
- __copy_to_user(ra.buf, cgc.buffer, CD_FRAMESIZE_RAW);
- ra.buf += CD_FRAMESIZE_RAW;
- ra.nframes--;
- lba++;
+ if (frames > ra.nframes)
+ frames = ra.nframes;
+ ret = cdrom_read_block(cdi, &cgc, lba, frames, 1, CD_FRAMESIZE_RAW);
+ if (ret)
+ break;
+ __copy_to_user(ra.buf, cgc.buffer,
+ CD_FRAMESIZE_RAW * frames);
+ ra.buf += (CD_FRAMESIZE_RAW * frames);
+ ra.nframes -= frames;
+ lba += frames;
}
kfree(cgc.buffer);
return ret;
next prev parent reply other threads:[~2001-03-15 13:05 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-03-14 14:17 [PATCH] fix a bug in ioctl(CDROMREADAUDIO) in cdrom.c in 2.2.18 Jani Jaakkola
2001-03-15 13:04 ` Pierre Etchemaite [this message]
2001-03-16 19:09 ` [PATCH] fix a bug in ioctl(CDROMREADAUDIO) in cdrom.c in 2.2 David Mansfield
2001-03-19 11:24 ` Jens Axboe
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=XFMail.20010315140400.petchema@concept-micro.com \
--to=petchema@concept-micro.com \
--cc=jjaakkol@cs.Helsinki.FI \
--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