* [PATCH] fix writing to unintended memory in pkt_generic_packet(); drivers/block/pktcdvd.c
@ 2007-11-06 22:43 Roel Kluin
2007-11-06 22:50 ` Al Viro
0 siblings, 1 reply; 4+ messages in thread
From: Roel Kluin @ 2007-11-06 22:43 UTC (permalink / raw)
To: lkml
CDROM_PACKET_SIZE is added as an offset to the pointer to unsigned char cmd[16].
The adjusted pointer is then used as a destination address in a call to
memset(). However, when CDROM_PACKET_SIZE is added to the pointer, it is
automatically scaled by the size of cmd, which is 16. This results in the call
to memset() writing to unintended memory.
Signed-off-by: Roel Kluin <12o3l@tiscali.nl>
---
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index a8130a4..548efcf 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -767,7 +767,7 @@ static int pkt_generic_packet(struct pktcdvd_device *pd, struct packet_command *
rq->cmd_len = COMMAND_SIZE(cgc->cmd[0]);
memcpy(rq->cmd, cgc->cmd, CDROM_PACKET_SIZE);
if (sizeof(rq->cmd) > CDROM_PACKET_SIZE)
- memset(rq->cmd + CDROM_PACKET_SIZE, 0, sizeof(rq->cmd) - CDROM_PACKET_SIZE);
+ memset((char *)rq->cmd + CDROM_PACKET_SIZE, 0, sizeof(rq->cmd) - CDROM_PACKET_SIZE);
rq->timeout = 60*HZ;
rq->cmd_type = REQ_TYPE_BLOCK_PC;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] fix writing to unintended memory in pkt_generic_packet(); drivers/block/pktcdvd.c
2007-11-06 22:43 [PATCH] fix writing to unintended memory in pkt_generic_packet(); drivers/block/pktcdvd.c Roel Kluin
@ 2007-11-06 22:50 ` Al Viro
2007-11-06 23:14 ` Roel Kluin
0 siblings, 1 reply; 4+ messages in thread
From: Al Viro @ 2007-11-06 22:50 UTC (permalink / raw)
To: Roel Kluin; +Cc: lkml
On Tue, Nov 06, 2007 at 11:43:12PM +0100, Roel Kluin wrote:
> CDROM_PACKET_SIZE is added as an offset to the pointer to unsigned char cmd[16].
> The adjusted pointer is then used as a destination address in a call to
> memset(). However, when CDROM_PACKET_SIZE is added to the pointer, it is
> automatically scaled by the size of cmd, which is 16. This results in the call
> to memset() writing to unintended memory.
What are you talking about? rq->cmd is an array, not a pointer to array.
When it occurs as an argument of +, it decays to pointer to array element.
Please, learn C.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] fix writing to unintended memory in pkt_generic_packet(); drivers/block/pktcdvd.c
2007-11-06 22:50 ` Al Viro
@ 2007-11-06 23:14 ` Roel Kluin
2007-11-06 23:34 ` Al Viro
0 siblings, 1 reply; 4+ messages in thread
From: Roel Kluin @ 2007-11-06 23:14 UTC (permalink / raw)
To: Al Viro; +Cc: lkml
Al Viro wrote:
> On Tue, Nov 06, 2007 at 11:43:12PM +0100, Roel Kluin wrote:
>> CDROM_PACKET_SIZE is added as an offset to the pointer to unsigned char cmd[16].
>> The adjusted pointer is then used as a destination address in a call to
>> memset(). However, when CDROM_PACKET_SIZE is added to the pointer, it is
>> automatically scaled by the size of cmd, which is 16. This results in the call
>> to memset() writing to unintended memory.
>
> What are you talking about? rq->cmd is an array, not a pointer to array.
> When it occurs as an argument of +, it decays to pointer to array element.
Ok, I misunderstood, but please...
> Please, learn C.
That's not a nice thing to say.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] fix writing to unintended memory in pkt_generic_packet(); drivers/block/pktcdvd.c
2007-11-06 23:14 ` Roel Kluin
@ 2007-11-06 23:34 ` Al Viro
0 siblings, 0 replies; 4+ messages in thread
From: Al Viro @ 2007-11-06 23:34 UTC (permalink / raw)
To: Roel Kluin; +Cc: lkml
On Wed, Nov 07, 2007 at 12:14:48AM +0100, Roel Kluin wrote:
> Al Viro wrote:
> > On Tue, Nov 06, 2007 at 11:43:12PM +0100, Roel Kluin wrote:
> >> CDROM_PACKET_SIZE is added as an offset to the pointer to unsigned char cmd[16].
> >> The adjusted pointer is then used as a destination address in a call to
> >> memset(). However, when CDROM_PACKET_SIZE is added to the pointer, it is
> >> automatically scaled by the size of cmd, which is 16. This results in the call
> >> to memset() writing to unintended memory.
> >
> > What are you talking about? rq->cmd is an array, not a pointer to array.
> > When it occurs as an argument of +, it decays to pointer to array element.
>
> Ok, I misunderstood, but please...
>
> > Please, learn C.
>
> That's not a nice thing to say.
Excuse me, but if you want to write in C, you will have to learn the language.
Really. Including the relationship between pointers and arrays. No way
around it, it's really basic stuff. Whether it's a nice thing to say or not,
it is true and I do not know more polite way to phrase that.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-11-06 23:34 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-06 22:43 [PATCH] fix writing to unintended memory in pkt_generic_packet(); drivers/block/pktcdvd.c Roel Kluin
2007-11-06 22:50 ` Al Viro
2007-11-06 23:14 ` Roel Kluin
2007-11-06 23:34 ` Al Viro
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox