* [patch] pch_gbe: memory corruption calling pch_gbe_validate_option()
@ 2012-03-01 7:17 Dan Carpenter
2012-03-01 22:24 ` David Miller
0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2012-03-01 7:17 UTC (permalink / raw)
To: Masayuki Ohtake
Cc: David S. Miller, Paul Gortmaker, Jeff Kirsher,
Michał Mirosław, netdev, kernel-janitors
pch_gbe_validate_option() modifies 32 bits of memory but we pass
&hw->phy.autoneg_advertised which only has 16 bits and &hw->mac.fc
which only has 8 bits.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
diff --git a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_param.c b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_param.c
index 9cb5f91..29e23be 100644
--- a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_param.c
+++ b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_param.c
@@ -321,10 +321,10 @@ static void pch_gbe_check_copper_options(struct pch_gbe_adapter *adapter)
pr_debug("AutoNeg specified along with Speed or Duplex, AutoNeg parameter ignored\n");
hw->phy.autoneg_advertised = opt.def;
} else {
- hw->phy.autoneg_advertised = AutoNeg;
- pch_gbe_validate_option(
- (int *)(&hw->phy.autoneg_advertised),
- &opt, adapter);
+ int tmp = AutoNeg;
+
+ pch_gbe_validate_option(&tmp, &opt, adapter);
+ hw->phy.autoneg_advertised = tmp;
}
}
@@ -495,9 +495,10 @@ void pch_gbe_check_options(struct pch_gbe_adapter *adapter)
.arg = { .l = { .nr = (int)ARRAY_SIZE(fc_list),
.p = fc_list } }
};
- hw->mac.fc = FlowControl;
- pch_gbe_validate_option((int *)(&hw->mac.fc),
- &opt, adapter);
+ int tmp = FlowControl;
+
+ pch_gbe_validate_option(&tmp, &opt, adapter);
+ hw->mac.fc = tmp;
}
pch_gbe_check_copper_options(adapter);
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [patch] pch_gbe: memory corruption calling pch_gbe_validate_option()
2012-03-01 7:17 [patch] pch_gbe: memory corruption calling pch_gbe_validate_option() Dan Carpenter
@ 2012-03-01 22:24 ` David Miller
2012-03-05 5:34 ` santosh prasad nayak
0 siblings, 1 reply; 4+ messages in thread
From: David Miller @ 2012-03-01 22:24 UTC (permalink / raw)
To: dan.carpenter
Cc: masa-korg, paul.gortmaker, jeffrey.t.kirsher, mirq-linux, netdev,
kernel-janitors
From: Dan Carpenter <dan.carpenter@oracle.com>
Date: Thu, 1 Mar 2012 10:17:08 +0300
> pch_gbe_validate_option() modifies 32 bits of memory but we pass
> &hw->phy.autoneg_advertised which only has 16 bits and &hw->mac.fc
> which only has 8 bits.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Applied.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch] pch_gbe: memory corruption calling pch_gbe_validate_option()
2012-03-01 22:24 ` David Miller
@ 2012-03-05 5:34 ` santosh prasad nayak
2012-03-05 6:33 ` Dan Carpenter
0 siblings, 1 reply; 4+ messages in thread
From: santosh prasad nayak @ 2012-03-05 5:34 UTC (permalink / raw)
To: David Miller
Cc: dan.carpenter, masa-korg, paul.gortmaker, jeffrey.t.kirsher,
mirq-linux, netdev, kernel-janitors
Dan,
Your fix may introduce new bug.
hw->phy.autoneg_advertised = tmp
Assigning signed integer to unsigned short leads to bit truncation.
Is it safe for both Big-endian and little endian format ?
AutoNeg is initialized with a Negative value (OPTION_UNSET)
Won't it create any issue with above assignment ?
The simpler fix is to make "autoneg_advertised" signed integer.
struct pch_gbe_phy_info {
u32 addr;
u32 id;
u32 revision;
u32 reset_delay_us;
u16 autoneg_advertised; // ==> int autoneg_advertised
};
Regards
Santosh
On Fri, Mar 2, 2012 at 3:54 AM, David Miller <davem@davemloft.net> wrote:
> From: Dan Carpenter <dan.carpenter@oracle.com>
> Date: Thu, 1 Mar 2012 10:17:08 +0300
>
>> pch_gbe_validate_option() modifies 32 bits of memory but we pass
>> &hw->phy.autoneg_advertised which only has 16 bits and &hw->mac.fc
>> which only has 8 bits.
>>
>> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>
> Applied.
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch] pch_gbe: memory corruption calling pch_gbe_validate_option()
2012-03-05 5:34 ` santosh prasad nayak
@ 2012-03-05 6:33 ` Dan Carpenter
0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2012-03-05 6:33 UTC (permalink / raw)
To: santosh prasad nayak
Cc: David Miller, masa-korg, paul.gortmaker, jeffrey.t.kirsher,
mirq-linux, netdev, kernel-janitors
[-- Attachment #1: Type: text/plain, Size: 1264 bytes --]
On Mon, Mar 05, 2012 at 11:04:49AM +0530, santosh prasad nayak wrote:
> Dan,
>
> Your fix may introduce new bug.
>
> hw->phy.autoneg_advertised = tmp
>
> Assigning signed integer to unsigned short leads to bit truncation.
In this case it doesn't. It's going to be 0x2f or less. I
obviously checked this before I submitted the patch.
> Is it safe for both Big-endian and little endian format ?
It's CPU endian in both cases.
>
> AutoNeg is initialized with a Negative value (OPTION_UNSET)
> Won't it create any issue with above assignment ?
>
Nope. It gets set to 0x2f inside pch_gbe_validate_option().
>
> The simpler fix is to make "autoneg_advertised" signed integer.
>
> struct pch_gbe_phy_info {
> u32 addr;
> u32 id;
> u32 revision;
> u32 reset_delay_us;
> u16 autoneg_advertised; // ==> int autoneg_advertised
> };
>
The better fix would be to change pch_gbe_validate_option() so it
isn't so easy to call improperly. I would have done that except
that probably we won't introduce many more callers, it seemed
like a lot of work and I don't have the hardware to test the
results.
regards,
dan carpenter
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-03-05 6:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-01 7:17 [patch] pch_gbe: memory corruption calling pch_gbe_validate_option() Dan Carpenter
2012-03-01 22:24 ` David Miller
2012-03-05 5:34 ` santosh prasad nayak
2012-03-05 6:33 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).