All of lore.kernel.org
 help / color / mirror / Atom feed
* Oops with mtd_dataflash driver in 3.3
@ 2012-03-30 10:51 Will Newton
  2012-04-13 15:58 ` Artem Bityutskiy
  0 siblings, 1 reply; 2+ messages in thread
From: Will Newton @ 2012-03-30 10:51 UTC (permalink / raw)
  To: linux-mtd; +Cc: Artem Bityutskiy

Hi all,

I'm seeing an oops in mtd_dataflash.c with Linux 3.3. What appears to
be happening is that otp_select_filemode calls mtd_read_fact_prot_reg
with -1 for offset and length and a NULL buffer to test if OTP
operations are supported. This finds its way down to otp_read in
mtd_dataflash.c and causes an oops when memcpying the returned data
into the NULL buf.

None of the checks in otp_read catches the negative length and offset.
Changing the length of the dummy read to 0 prevents the oops, but I'm
not sure if it is the preferred solution. Would this change be
acceptable?

diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 50c6a1e..853744d 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -369,7 +369,7 @@ static int otp_select_filemode(struct
mtd_file_info *mfi, int mode)
         * Make a fake call to mtd_read_fact_prot_reg() to check if OTP
         * operations are supported.
         */
-       if (mtd_read_fact_prot_reg(mtd, -1, -1, &retlen, NULL) == -EOPNOTSUPP)
+       if (mtd_read_fact_prot_reg(mtd, -1, 0, &retlen, NULL) == -EOPNOTSUPP)
                return -EOPNOTSUPP;

        switch (mode) {

Thanks,

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: Oops with mtd_dataflash driver in 3.3
  2012-03-30 10:51 Oops with mtd_dataflash driver in 3.3 Will Newton
@ 2012-04-13 15:58 ` Artem Bityutskiy
  0 siblings, 0 replies; 2+ messages in thread
From: Artem Bityutskiy @ 2012-04-13 15:58 UTC (permalink / raw)
  To: Will Newton; +Cc: linux-mtd

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

On Fri, 2012-03-30 at 11:51 +0100, Will Newton wrote:
> Hi all,
> 
> I'm seeing an oops in mtd_dataflash.c with Linux 3.3. What appears to
> be happening is that otp_select_filemode calls mtd_read_fact_prot_reg
> with -1 for offset and length and a NULL buffer to test if OTP
> operations are supported. This finds its way down to otp_read in
> mtd_dataflash.c and causes an oops when memcpying the returned data
> into the NULL buf.

Hi, good catch, thanks!

I've added "Cc: stable@krnel.org [3.3+]" and pushed to l2-mtd.git,
thanks you.

But note, you should add your Signed-off-by when sending patches.
Also this patch is line-wrapped so I had to do a small surgery to apply
it. Try to save it from your mailbox and apply with 'git am'.

Anyway, thanks for the catch.

-- 
Best Regards,
Artem Bityutskiy

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-04-13 15:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-30 10:51 Oops with mtd_dataflash driver in 3.3 Will Newton
2012-04-13 15:58 ` Artem Bityutskiy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.