linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: 2.6.37-rc7: Regression: b43: crashes in hwrng_register()
       [not found]               ` <4D1D0C61.9050800@lwfinger.net>
@ 2010-12-31  0:37                 ` Herbert Xu
  2010-12-31  0:46                   ` Larry Finger
  0 siblings, 1 reply; 29+ messages in thread
From: Herbert Xu @ 2010-12-31  0:37 UTC (permalink / raw)
  To: Larry Finger
  Cc: Mario 'BitKoenig' Holbe, Matt Mackall, LKML,
	Linux Crypto Mailing List, Harald Welte, Michal Ludvig

On Thu, Dec 30, 2010 at 04:49:05PM -0600, Larry Finger wrote:
>
> Do you see any problems in the code in drivers/net/wireless/b43/main.c or
> drivers/char/hw_random/via-rng.c. As the latter seems to make b43 fail, I am
> suspecting via-rng, but I have no proof.

My suspicion is that VIA's xstore is writing more than 4 bytes as
the list pointer happens to lie immediately after rng->priv which
is where xstore is writing to.

Harald, do you know whether this is documented or is this a known
errata item?

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: 2.6.37-rc7: Regression: b43: crashes in hwrng_register()
  2010-12-31  0:37                 ` 2.6.37-rc7: Regression: b43: crashes in hwrng_register() Herbert Xu
@ 2010-12-31  0:46                   ` Larry Finger
  2010-12-31  2:25                     ` Mario 'BitKoenig' Holbe
  0 siblings, 1 reply; 29+ messages in thread
From: Larry Finger @ 2010-12-31  0:46 UTC (permalink / raw)
  To: Herbert Xu
  Cc: Mario 'BitKoenig' Holbe, Matt Mackall, LKML,
	Linux Crypto Mailing List, Harald Welte, Michal Ludvig

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

On 12/30/2010 06:37 PM, Herbert Xu wrote:
> On Thu, Dec 30, 2010 at 04:49:05PM -0600, Larry Finger wrote:
>>
>> Do you see any problems in the code in drivers/net/wireless/b43/main.c or
>> drivers/char/hw_random/via-rng.c. As the latter seems to make b43 fail, I am
>> suspecting via-rng, but I have no proof.
> 
> My suspicion is that VIA's xstore is writing more than 4 bytes as
> the list pointer happens to lie immediately after rng->priv which
> is where xstore is writing to.
> 
> Harald, do you know whether this is documented or is this a known
> errata item?

The following patch should be able to test if xstore is overwriting the list
pointer.

Larry
---

Index: wireless-testing/include/linux/hw_random.h
===================================================================
--- wireless-testing.orig/include/linux/hw_random.h
+++ wireless-testing/include/linux/hw_random.h
@@ -38,6 +38,7 @@ struct hwrng {
 	int (*data_read)(struct hwrng *rng, u32 *data);
 	int (*read)(struct hwrng *rng, void *data, size_t max, bool wait);
 	unsigned long priv;
+	char junk[12];

 	/* internal. */
 	struct list_head list;



[-- Attachment #2: hwrng_debug --]
[-- Type: text/plain, Size: 454 bytes --]

Index: wireless-testing/include/linux/hw_random.h
===================================================================
--- wireless-testing.orig/include/linux/hw_random.h
+++ wireless-testing/include/linux/hw_random.h
@@ -38,6 +38,7 @@ struct hwrng {
 	int (*data_read)(struct hwrng *rng, u32 *data);
 	int (*read)(struct hwrng *rng, void *data, size_t max, bool wait);
 	unsigned long priv;
+	char junk[12];
 
 	/* internal. */
 	struct list_head list;


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

* Re: 2.6.37-rc7: Regression: b43: crashes in hwrng_register()
  2010-12-31  0:46                   ` Larry Finger
@ 2010-12-31  2:25                     ` Mario 'BitKoenig' Holbe
  2010-12-31  2:46                       ` Herbert Xu
  0 siblings, 1 reply; 29+ messages in thread
From: Mario 'BitKoenig' Holbe @ 2010-12-31  2:25 UTC (permalink / raw)
  To: Larry Finger
  Cc: Herbert Xu, Matt Mackall, LKML, Linux Crypto Mailing List,
	Harald Welte, Michal Ludvig


[-- Attachment #1.1: Type: text/plain, Size: 1109 bytes --]

On Thu, Dec 30, 2010 at 06:46:31PM -0600, Larry Finger wrote:
> On 12/30/2010 06:37 PM, Herbert Xu wrote:
> > My suspicion is that VIA's xstore is writing more than 4 bytes as
> > the list pointer happens to lie immediately after rng->priv which
> > is where xstore is writing to.
> > 
> > Harald, do you know whether this is documented or is this a known
> > errata item?
> 
> The following patch should be able to test if xstore is overwriting the list
> pointer.

Confirmed. No crashes with the junk buffer in action.
I applied both patches (dump_stack() in hwrng_register() and junk[]
after priv data) to vanilla 2.6.37-rc7 and tested both: via-rng and my
via+rng2 as well as via-rng and b43-rng - no crashes. The (previously
also crashing) `cat rng_available' does survive as well:

$ cat /sys/devices/virtual/misc/hw_random/rng_available
via b43_phy0 via2 
$ 

Attached 2 dmesg excerpts.


regards & g'nite
   Mario
-- 
Tower: "Say fuelstate." Pilot: "Fuelstate."
Tower: "Say again." Pilot: "Again."
Tower: "Arghl, give me your fuel!" Pilot: "Sorry, need it by myself..."

[-- Attachment #1.2: 2.6.37-rc7+via-rng2.dmesg --]
[-- Type: text/plain, Size: 948 bytes --]

[   11.606134] VIA RNG detected
[   11.606139] Calling hwrng_register
[   11.606145] Pid: 752, comm: modprobe Not tainted 2.6.37-rc7-self #1
[   11.606149] Call Trace:
[   11.606159]  [<f90c33ac>] ? hwrng_register+0x2c/0x14d [rng_core]
[   11.606167]  [<f90d0023>] ? mod_init+0x23/0x3b [via_rng]
[   11.606176]  [<c1003069>] ? do_one_initcall+0x68/0x10f
[   11.606186]  [<c105f0d3>] ? sys_init_module+0xca5/0xe36
[   11.606214]  [<c1008b1f>] ? sysenter_do_call+0x12/0x28
...
[   92.687121] VIA RNG detected
[   92.687126] Calling hwrng_register
[   92.687132] Pid: 2698, comm: modprobe Not tainted 2.6.37-rc7-self #1
[   92.687136] Call Trace:
[   92.687152]  [<f90c33ac>] ? hwrng_register+0x2c/0x14d [rng_core]
[   92.687161]  [<f8274023>] ? mod_init+0x23/0x3b [via_rng2]
[   92.687171]  [<c1003069>] ? do_one_initcall+0x68/0x10f
[   92.687181]  [<c105f0d3>] ? sys_init_module+0xca5/0xe36
[   92.687227]  [<c1008b1f>] ? sysenter_do_call+0x12/0x28

[-- Attachment #1.3: 2.6.37-rc7+via-rng2+b43.dmesg --]
[-- Type: text/plain, Size: 3236 bytes --]

[   11.686811] VIA RNG detected
[   11.686816] Calling hwrng_register
[   11.686822] Pid: 807, comm: modprobe Not tainted 2.6.37-rc7-self #1
[   11.686826] Call Trace:
[   11.686839]  [<f8fb23ac>] ? hwrng_register+0x2c/0x14d [rng_core]
[   11.686847]  [<f923f023>] ? mod_init+0x23/0x3b [via_rng]
[   11.686856]  [<c1003069>] ? do_one_initcall+0x68/0x10f
[   11.686867]  [<c105f0d3>] ? sys_init_module+0xca5/0xe36
[   11.686897]  [<c1008b1f>] ? sysenter_do_call+0x12/0x28
...
[   29.964239] b43-pci-bridge 0000:02:00.0: PCI: Disallowing DAC for device
[   29.964251] b43-phy0: DMA mask fallback from 64-bit to 32-bit
[   29.984626] Calling hwrng_register
[   29.984640] Pid: 1550, comm: NetworkManager Not tainted 2.6.37-rc7-self #1
[   29.984648] Call Trace:
[   29.984688]  [<f8fb23ac>] ? hwrng_register+0x2c/0x14d [rng_core]
[   29.984729]  [<f8ffe879>] ? b43_wireless_core_init+0xd12/0xddf [b43]
[   29.984759]  [<f8ffed73>] ? b43_op_start+0xf8/0x142 [b43]
[   29.984796]  [<f8d463da>] ? cfg80211_netdev_notifier_call+0x342/0x355 [cfg80211]
[   29.984853]  [<f8f1a889>] ? ieee80211_do_open+0xed/0x45f [mac80211]
[   29.984886]  [<f8f19e7a>] ? ieee80211_check_concurrent_iface+0x1c/0x135 [mac80211]
[   29.984908]  [<c1203247>] ? __dev_open+0x7d/0xa7
[   29.984922]  [<c1201c10>] ? __dev_change_flags+0x9a/0x10d
[   29.984934]  [<c120319f>] ? dev_change_flags+0x10/0x3b
[   29.984949]  [<c120d207>] ? do_setlink+0x23e/0x532
[   29.984965]  [<c120d5cb>] ? rtnl_setlink+0xd0/0xe1
[   29.984986]  [<c114f000>] ? clear_user+0x2b/0x43
[   29.984997]  [<c120d4fb>] ? rtnl_setlink+0x0/0xe1
[   29.985008]  [<c120cd32>] ? rtnetlink_rcv_msg+0x186/0x19c
[   29.985020]  [<c120cbac>] ? rtnetlink_rcv_msg+0x0/0x19c
[   29.985034]  [<c121bda8>] ? netlink_rcv_skb+0x2d/0x72
[   29.985046]  [<c120cba6>] ? rtnetlink_rcv+0x18/0x1e
[   29.985056]  [<c121bbfc>] ? netlink_unicast+0xba/0x10e
[   29.985068]  [<c121c700>] ? netlink_sendmsg+0x23d/0x256
[   29.985082]  [<c11f53a6>] ? __sock_sendmsg+0x48/0x4e
[   29.985093]  [<c11f560f>] ? sock_sendmsg+0x78/0x8f
[   29.985105]  [<c11f560f>] ? sock_sendmsg+0x78/0x8f
[   29.985119]  [<c10cf5dd>] ? d_kill+0x38/0x3d
[   29.985137]  [<c11fd48c>] ? verify_iovec+0x3d/0x79
[   29.985147]  [<c11f5e0d>] ? sys_sendmsg+0x15f/0x1c1
[   29.985159]  [<c11f5a44>] ? sockfd_lookup_light+0x13/0x3f
[   29.985170]  [<c11f60a5>] ? sys_sendto+0xfd/0x121
[   29.985182]  [<c11f996b>] ? sk_prot_alloc+0x62/0xd6
[   29.985195]  [<c10079ee>] ? __switch_to+0x6f/0xe2
[   29.985213]  [<c129ced6>] ? schedule+0x579/0x5b6
[   29.985225]  [<c11f5ca3>] ? sys_recvmsg+0x3c/0x47
[   29.985236]  [<c11f707d>] ? sys_socketcall+0x17f/0x1cb
[   29.985249]  [<c1008b1f>] ? sysenter_do_call+0x12/0x28
[   29.987285] ADDRCONF(NETDEV_UP): wlan0: link is not ready
...
[   99.003298] VIA RNG detected
[   99.003303] Calling hwrng_register
[   99.003309] Pid: 2797, comm: modprobe Not tainted 2.6.37-rc7-self #1
[   99.003313] Call Trace:
[   99.003332]  [<f8fb23ac>] ? hwrng_register+0x2c/0x14d [rng_core]
[   99.003341]  [<f8281023>] ? mod_init+0x23/0x3b [via_rng2]
[   99.003350]  [<c1003069>] ? do_one_initcall+0x68/0x10f
[   99.003360]  [<c105f0d3>] ? sys_init_module+0xca5/0xe36
[   99.003403]  [<c1008b1f>] ? sysenter_do_call+0x12/0x28

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

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

* Re: 2.6.37-rc7: Regression: b43: crashes in hwrng_register()
  2010-12-31  2:25                     ` Mario 'BitKoenig' Holbe
@ 2010-12-31  2:46                       ` Herbert Xu
  2010-12-31  8:51                         ` Mario 'BitKoenig' Holbe
  0 siblings, 1 reply; 29+ messages in thread
From: Herbert Xu @ 2010-12-31  2:46 UTC (permalink / raw)
  To: Mario 'BitKoenig' Holbe, Larry Finger, Matt Mackall, LKML,
	Linux 

On Fri, Dec 31, 2010 at 03:25:51AM +0100, Mario 'BitKoenig' Holbe wrote:
>
> Confirmed. No crashes with the junk buffer in action.
> I applied both patches (dump_stack() in hwrng_register() and junk[]
> after priv data) to vanilla 2.6.37-rc7 and tested both: via-rng and my
> via+rng2 as well as via-rng and b43-rng - no crashes. The (previously
> also crashing) `cat rng_available' does survive as well:
> 
> $ cat /sys/devices/virtual/misc/hw_random/rng_available
> via b43_phy0 via2 
> $ 
> 
> Attached 2 dmesg excerpts.

Thanks for checking.  Can you provide the output of

	cat /proc/cpuinfo

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: 2.6.37-rc7: Regression: b43: crashes in hwrng_register()
  2010-12-31  2:46                       ` Herbert Xu
@ 2010-12-31  8:51                         ` Mario 'BitKoenig' Holbe
  2011-01-04  4:33                           ` Herbert Xu
  0 siblings, 1 reply; 29+ messages in thread
From: Mario 'BitKoenig' Holbe @ 2010-12-31  8:51 UTC (permalink / raw)
  To: Herbert Xu
  Cc: Larry Finger, Matt Mackall, LKML, Linux Crypto Mailing List,
	Harald Welte, Michal Ludvig


[-- Attachment #1.1: Type: text/plain, Size: 324 bytes --]

On Fri, Dec 31, 2010 at 01:46:53PM +1100, Herbert Xu wrote:
> Thanks for checking.  Can you provide the output of
> 	cat /proc/cpuinfo

attached.


Mario
-- 
The only thing to be scared of, son, is tomorrow.
I don't live for tomorrow. Never saw the fun in it.
                       -- Denny Crane, Boston Legal

[-- Attachment #1.2: cpuinfo --]
[-- Type: text/plain, Size: 654 bytes --]

processor	: 0
vendor_id	: CentaurHauls
cpu family	: 6
model		: 15
model name	: VIA Nano processor U2250 (1.6GHz Capable)
stepping	: 3
cpu MHz		: 1600.000
cache size	: 1024 KB
fdiv_bug	: no
hlt_bug		: no
f00f_bug	: no
coma_bug	: no
fpu		: yes
fpu_exception	: yes
cpuid level	: 10
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat clflush acpi mmx fxsr sse sse2 ss tm syscall nx lm constant_tsc up rep_good pni monitor vmx est tm2 ssse3 cx16 xtpr rng rng_en ace ace_en ace2 phe phe_en lahf_lm
bogomips	: 3192.08
clflush size	: 64
cache_alignment	: 128
address sizes	: 36 bits physical, 48 bits virtual
power management:


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

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

* Re: 2.6.37-rc7: Regression: b43: crashes in hwrng_register()
  2010-12-31  8:51                         ` Mario 'BitKoenig' Holbe
@ 2011-01-04  4:33                           ` Herbert Xu
  2011-01-04 12:19                             ` Mario 'BitKoenig' Holbe
  0 siblings, 1 reply; 29+ messages in thread
From: Herbert Xu @ 2011-01-04  4:33 UTC (permalink / raw)
  To: Mario 'BitKoenig' Holbe, Larry Finger, Matt Mackall, LKML,
	Linux 

On Fri, Dec 31, 2010 at 09:51:04AM +0100, Mario 'BitKoenig' Holbe wrote:
> On Fri, Dec 31, 2010 at 01:46:53PM +1100, Herbert Xu wrote:
> > Thanks for checking.  Can you provide the output of
> > 	cat /proc/cpuinfo
> 
> attached.

Thanks.

Can you please test the following patch?

diff --git a/drivers/char/hw_random/via-rng.c b/drivers/char/hw_random/via-rng.c
index 794aacb..507a57f 100644
--- a/drivers/char/hw_random/via-rng.c
+++ b/drivers/char/hw_random/via-rng.c
@@ -24,6 +24,7 @@
  * warranty of any kind, whether express or implied.
  */
 
+#include <crypto/padlock.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/hw_random.h>
@@ -34,7 +35,6 @@
 #include <asm/i387.h>
 
 
-#define PFX	KBUILD_MODNAME ": "
 
 
 enum {
@@ -90,8 +90,10 @@ static inline u32 xstore(u32 *addr, u32 edx_in)
 
 static int via_rng_data_present(struct hwrng *rng, int wait)
 {
+	char buf[16 + PADLOCK_ALIGNMENT - STACK_ALIGN] __attribute__
+		((aligned(STACK_ALIGN)));
+	u32 *via_rng_datum = (u32 *)PTR_ALIGN(&buf[0], PADLOCK_ALIGNMENT);
 	u32 bytes_out;
-	u32 *via_rng_datum = (u32 *)(&rng->priv);
 	int i;
 
 	/* We choose the recommended 1-byte-per-instruction RNG rate,
@@ -115,6 +117,7 @@ static int via_rng_data_present(struct hwrng *rng, int wait)
 			break;
 		udelay(10);
 	}
+	rng->priv = *via_rng_datum;
 	return bytes_out ? 1 : 0;
 }
 
diff --git a/drivers/crypto/padlock-aes.c b/drivers/crypto/padlock-aes.c
index 2e992bc..2e56508 100644
--- a/drivers/crypto/padlock-aes.c
+++ b/drivers/crypto/padlock-aes.c
@@ -9,6 +9,7 @@
 
 #include <crypto/algapi.h>
 #include <crypto/aes.h>
+#include <crypto/padlock.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/types.h>
@@ -21,7 +22,6 @@
 #include <asm/byteorder.h>
 #include <asm/processor.h>
 #include <asm/i387.h>
-#include "padlock.h"
 
 /*
  * Number of data blocks actually fetched for each xcrypt insn.
diff --git a/drivers/crypto/padlock-sha.c b/drivers/crypto/padlock-sha.c
index d3a27e0..adf075b 100644
--- a/drivers/crypto/padlock-sha.c
+++ b/drivers/crypto/padlock-sha.c
@@ -13,6 +13,7 @@
  */
 
 #include <crypto/internal/hash.h>
+#include <crypto/padlock.h>
 #include <crypto/sha.h>
 #include <linux/err.h>
 #include <linux/module.h>
@@ -22,13 +23,6 @@
 #include <linux/kernel.h>
 #include <linux/scatterlist.h>
 #include <asm/i387.h>
-#include "padlock.h"
-
-#ifdef CONFIG_64BIT
-#define STACK_ALIGN 16
-#else
-#define STACK_ALIGN 4
-#endif
 
 struct padlock_sha_desc {
 	struct shash_desc fallback;
diff --git a/drivers/crypto/padlock.h b/drivers/crypto/padlock.h
deleted file mode 100644
index b728e45..0000000
--- a/drivers/crypto/padlock.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Driver for VIA PadLock
- *
- * Copyright (c) 2004 Michal Ludvig <michal@logix.cz>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option) 
- * any later version.
- *
- */
-
-#ifndef _CRYPTO_PADLOCK_H
-#define _CRYPTO_PADLOCK_H
-
-#define PADLOCK_ALIGNMENT 16
-
-#define PFX	"padlock: "
-
-#define PADLOCK_CRA_PRIORITY	300
-#define PADLOCK_COMPOSITE_PRIORITY 400
-
-#endif	/* _CRYPTO_PADLOCK_H */
diff --git a/include/crypto/padlock.h b/include/crypto/padlock.h
new file mode 100644
index 0000000..d2cfa2e
--- /dev/null
+++ b/include/crypto/padlock.h
@@ -0,0 +1,29 @@
+/*
+ * Driver for VIA PadLock
+ *
+ * Copyright (c) 2004 Michal Ludvig <michal@logix.cz>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option) 
+ * any later version.
+ *
+ */
+
+#ifndef _CRYPTO_PADLOCK_H
+#define _CRYPTO_PADLOCK_H
+
+#define PADLOCK_ALIGNMENT 16
+
+#define PFX	KBUILD_MODNAME ": "
+
+#define PADLOCK_CRA_PRIORITY	300
+#define PADLOCK_COMPOSITE_PRIORITY 400
+
+#ifdef CONFIG_64BIT
+#define STACK_ALIGN 16
+#else
+#define STACK_ALIGN 4
+#endif
+
+#endif	/* _CRYPTO_PADLOCK_H */

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: 2.6.37-rc7: Regression: b43: crashes in hwrng_register()
  2011-01-04  4:33                           ` Herbert Xu
@ 2011-01-04 12:19                             ` Mario 'BitKoenig' Holbe
  2011-01-04 12:38                               ` Herbert Xu
  0 siblings, 1 reply; 29+ messages in thread
From: Mario 'BitKoenig' Holbe @ 2011-01-04 12:19 UTC (permalink / raw)
  To: Herbert Xu
  Cc: Larry Finger, Matt Mackall, LKML, Linux Crypto Mailing List,
	Harald Welte, Michal Ludvig

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

Hello Herbert,

On Tue, Jan 04, 2011 at 03:33:38PM +1100, Herbert Xu wrote:
> Can you please test the following patch?
> diff --git a/drivers/char/hw_random/via-rng.c b/drivers/char/hw_random/via-rng.c

Hmmm, yes - the patch fixes the crashes, i.e. no more crashes with
either sequence of module-loading, cat rng_available works as well,
but...

Having this patch active rngd complains:
	rngd[1435]: rngd 2-unofficial-mt.13 starting up...
	rngd[1435]: block failed FIPS test: 0x1f
	rngd[1435]: block failed FIPS test: 0x1f
	...
	rngd[1435]: stats: entropy added to kernel pool: 0
	rngd[1435]: stats: FIPS 140-2 successes: 0
	rngd[1435]: stats: FIPS 140-2 failures: 10

It doesn't do this without the patch.
The only available rng was via, I did blacklist the others just to be
sure.


regards
   Mario
-- 
The social dynamics of the net are a direct consequence of the fact that
nobody has yet developed a Remote Strangulation Protocol.  -- Larry Wall

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

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

* Re: 2.6.37-rc7: Regression: b43: crashes in hwrng_register()
  2011-01-04 12:19                             ` Mario 'BitKoenig' Holbe
@ 2011-01-04 12:38                               ` Herbert Xu
  2011-01-04 12:57                                 ` Mario 'BitKoenig' Holbe
  0 siblings, 1 reply; 29+ messages in thread
From: Herbert Xu @ 2011-01-04 12:38 UTC (permalink / raw)
  To: Mario 'BitKoenig' Holbe, Larry Finger, Matt Mackall, LKML,
	Linux 

On Tue, Jan 04, 2011 at 01:19:57PM +0100, Mario 'BitKoenig' Holbe wrote:
>
> Hmmm, yes - the patch fixes the crashes, i.e. no more crashes with
> either sequence of module-loading, cat rng_available works as well,
> but...
> 
> Having this patch active rngd complains:
> 	rngd[1435]: rngd 2-unofficial-mt.13 starting up...
> 	rngd[1435]: block failed FIPS test: 0x1f
> 	rngd[1435]: block failed FIPS test: 0x1f
> 	...
> 	rngd[1435]: stats: entropy added to kernel pool: 0
> 	rngd[1435]: stats: FIPS 140-2 successes: 0
> 	rngd[1435]: stats: FIPS 140-2 failures: 10
> 
> It doesn't do this without the patch.
> The only available rng was via, I did blacklist the others just to be
> sure.

Hmm, can you print out what it's actually producing (e.g., by
stracing rngd)?

Can you also double-check that this doesn't happen with Larry's
patch?

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: 2.6.37-rc7: Regression: b43: crashes in hwrng_register()
  2011-01-04 12:38                               ` Herbert Xu
@ 2011-01-04 12:57                                 ` Mario 'BitKoenig' Holbe
  2011-01-04 22:42                                   ` Herbert Xu
  0 siblings, 1 reply; 29+ messages in thread
From: Mario 'BitKoenig' Holbe @ 2011-01-04 12:57 UTC (permalink / raw)
  To: Herbert Xu
  Cc: Larry Finger, Matt Mackall, LKML, Linux Crypto Mailing List,
	Harald Welte, Michal Ludvig

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

On Tue, Jan 04, 2011 at 11:38:24PM +1100, Herbert Xu wrote:
> On Tue, Jan 04, 2011 at 01:19:57PM +0100, Mario 'BitKoenig' Holbe wrote:
> >
> > Hmmm, yes - the patch fixes the crashes, i.e. no more crashes with
> > either sequence of module-loading, cat rng_available works as well,
> > but...
> > 
> > Having this patch active rngd complains:
> > 	rngd[1435]: rngd 2-unofficial-mt.13 starting up...
> > 	rngd[1435]: block failed FIPS test: 0x1f
> > 	rngd[1435]: block failed FIPS test: 0x1f
> > 	...
> > 	rngd[1435]: stats: entropy added to kernel pool: 0
> > 	rngd[1435]: stats: FIPS 140-2 successes: 0
> > 	rngd[1435]: stats: FIPS 140-2 failures: 10
> > 
> > It doesn't do this without the patch.
> > The only available rng was via, I did blacklist the others just to be
> > sure.
> 
> Hmm, can you print out what it's actually producing (e.g., by
> stracing rngd)?

# ps -ef | grep 'rng[d]'
# cat /sys/devices/virtual/misc/hw_random/rng_available
via 
# hexdump -n 512 -C /dev/hwrng
00000000  00 ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00000010  ff ff ff ff ff ff ff 00  00 00 00 00 00 00 00 00  |................|
00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000200
# hexdump -n 512 -C /dev/hwrng
00000000  00 ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00000010  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
*
00000070  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000200
# hexdump -n 1024 -C /dev/hwrng
00000000  00 ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00000010  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
*
00000060  ff ff ff ff 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000070  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000400
# hexdump -n 1024 -C /dev/hwrng
00000000  00 ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00000010  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
*
00000070  ff 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000080  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000400
#                                                                                                                          
> Can you also double-check that this doesn't happen with Larry's
> patch?

Nope, it doesn't do this with Larry's patch.


Mario
-- 
The Encyclopedia Galactica, in its chapter on Love states that it is far
too complicated to define.
The Hitchhiker's Guide to the Galaxy has this to say on the subject of
love: Avoid, if at all possible.

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

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

* Re: 2.6.37-rc7: Regression: b43: crashes in hwrng_register()
  2011-01-04 12:57                                 ` Mario 'BitKoenig' Holbe
@ 2011-01-04 22:42                                   ` Herbert Xu
  2011-01-04 23:06                                     ` Mario 'BitKoenig' Holbe
  2011-01-05  0:14                                     ` 2.6.37-rc7: Regression: b43: crashes in hwrng_register() Larry Finger
  0 siblings, 2 replies; 29+ messages in thread
From: Herbert Xu @ 2011-01-04 22:42 UTC (permalink / raw)
  To: Mario 'BitKoenig' Holbe, Larry Finger, Matt Mackall, LKML,
	Linux 

On Tue, Jan 04, 2011 at 01:57:22PM +0100, Mario 'BitKoenig' Holbe wrote:
>
> # hexdump -n 512 -C /dev/hwrng
> 00000000  00 ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
> 00000010  ff ff ff ff ff ff ff 00  00 00 00 00 00 00 00 00  |................|
> 00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
> *

Weird.

Can you please try this patch against vanilla to print out the
raw output of xstore?

diff --git a/drivers/char/hw_random/via-rng.c b/drivers/char/hw_random/via-rng.c
index 794aacb..4408d4e 100644
--- a/drivers/char/hw_random/via-rng.c
+++ b/drivers/char/hw_random/via-rng.c
@@ -24,6 +24,7 @@
  * warranty of any kind, whether express or implied.
  */
 
+#include <crypto/padlock.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/hw_random.h>
@@ -34,7 +35,6 @@
 #include <asm/i387.h>
 
 
-#define PFX	KBUILD_MODNAME ": "
 
 
 enum {
@@ -85,13 +85,16 @@ static inline u32 xstore(u32 *addr, u32 edx_in)
 		:"D"(addr), "d"(edx_in));
 
 	irq_ts_restore(ts_state);
+	printk(KERN_DEBUG "0x%x\n", *addr);
 	return eax_out;
 }
 
 static int via_rng_data_present(struct hwrng *rng, int wait)
 {
+	char buf[16 + PADLOCK_ALIGNMENT - STACK_ALIGN] __attribute__
+		((aligned(STACK_ALIGN)));
+	u32 *via_rng_datum = (u32 *)PTR_ALIGN(&buf[0], PADLOCK_ALIGNMENT);
 	u32 bytes_out;
-	u32 *via_rng_datum = (u32 *)(&rng->priv);
 	int i;
 
 	/* We choose the recommended 1-byte-per-instruction RNG rate,
@@ -115,6 +118,7 @@ static int via_rng_data_present(struct hwrng *rng, int wait)
 			break;
 		udelay(10);
 	}
+	rng->priv = *via_rng_datum;
 	return bytes_out ? 1 : 0;
 }
 
diff --git a/drivers/crypto/padlock-aes.c b/drivers/crypto/padlock-aes.c
index 2e992bc..2e56508 100644
--- a/drivers/crypto/padlock-aes.c
+++ b/drivers/crypto/padlock-aes.c
@@ -9,6 +9,7 @@
 
 #include <crypto/algapi.h>
 #include <crypto/aes.h>
+#include <crypto/padlock.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/types.h>
@@ -21,7 +22,6 @@
 #include <asm/byteorder.h>
 #include <asm/processor.h>
 #include <asm/i387.h>
-#include "padlock.h"
 
 /*
  * Number of data blocks actually fetched for each xcrypt insn.
diff --git a/drivers/crypto/padlock-sha.c b/drivers/crypto/padlock-sha.c
index d3a27e0..adf075b 100644
--- a/drivers/crypto/padlock-sha.c
+++ b/drivers/crypto/padlock-sha.c
@@ -13,6 +13,7 @@
  */
 
 #include <crypto/internal/hash.h>
+#include <crypto/padlock.h>
 #include <crypto/sha.h>
 #include <linux/err.h>
 #include <linux/module.h>
@@ -22,13 +23,6 @@
 #include <linux/kernel.h>
 #include <linux/scatterlist.h>
 #include <asm/i387.h>
-#include "padlock.h"
-
-#ifdef CONFIG_64BIT
-#define STACK_ALIGN 16
-#else
-#define STACK_ALIGN 4
-#endif
 
 struct padlock_sha_desc {
 	struct shash_desc fallback;
diff --git a/drivers/crypto/padlock.h b/drivers/crypto/padlock.h
deleted file mode 100644
index b728e45..0000000
--- a/drivers/crypto/padlock.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Driver for VIA PadLock
- *
- * Copyright (c) 2004 Michal Ludvig <michal@logix.cz>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option) 
- * any later version.
- *
- */
-
-#ifndef _CRYPTO_PADLOCK_H
-#define _CRYPTO_PADLOCK_H
-
-#define PADLOCK_ALIGNMENT 16
-
-#define PFX	"padlock: "
-
-#define PADLOCK_CRA_PRIORITY	300
-#define PADLOCK_COMPOSITE_PRIORITY 400
-
-#endif	/* _CRYPTO_PADLOCK_H */
diff --git a/include/crypto/padlock.h b/include/crypto/padlock.h
new file mode 100644
index 0000000..d2cfa2e
--- /dev/null
+++ b/include/crypto/padlock.h
@@ -0,0 +1,29 @@
+/*
+ * Driver for VIA PadLock
+ *
+ * Copyright (c) 2004 Michal Ludvig <michal@logix.cz>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option) 
+ * any later version.
+ *
+ */
+
+#ifndef _CRYPTO_PADLOCK_H
+#define _CRYPTO_PADLOCK_H
+
+#define PADLOCK_ALIGNMENT 16
+
+#define PFX	KBUILD_MODNAME ": "
+
+#define PADLOCK_CRA_PRIORITY	300
+#define PADLOCK_COMPOSITE_PRIORITY 400
+
+#ifdef CONFIG_64BIT
+#define STACK_ALIGN 16
+#else
+#define STACK_ALIGN 4
+#endif
+
+#endif	/* _CRYPTO_PADLOCK_H */

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: 2.6.37-rc7: Regression: b43: crashes in hwrng_register()
  2011-01-04 22:42                                   ` Herbert Xu
@ 2011-01-04 23:06                                     ` Mario 'BitKoenig' Holbe
  2011-01-04 23:26                                       ` Larry Finger
                                                         ` (2 more replies)
  2011-01-05  0:14                                     ` 2.6.37-rc7: Regression: b43: crashes in hwrng_register() Larry Finger
  1 sibling, 3 replies; 29+ messages in thread
From: Mario 'BitKoenig' Holbe @ 2011-01-04 23:06 UTC (permalink / raw)
  To: Herbert Xu
  Cc: Larry Finger, Matt Mackall, LKML, Linux Crypto Mailing List,
	Harald Welte, Michal Ludvig

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

On Wed, Jan 05, 2011 at 09:42:38AM +1100, Herbert Xu wrote:
> Can you please try this patch against vanilla to print out the
> raw output of xstore?

# ps -ef | grep 'rng[d]'
# cat /sys/devices/virtual/misc/hw_random/rng_available
via 
# hexdump -n 16 -C /dev/hwrng
00000000  00 ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00000010
# 

kern.log meanwhile (lines numbered):
     1  Jan  4 23:56:40 ideapad kernel: [  151.714225] 0x0
     2  Jan  4 23:56:40 ideapad kernel: [  151.714236] 0xffffffff
     3  Jan  4 23:56:40 ideapad kernel: [  151.714239] 0x0
     4  Jan  4 23:56:40 ideapad kernel: [  151.714251] 0xffffffff
...
   233  Jan  4 23:56:40 ideapad kernel: [  151.715967] 0x0
   234  Jan  4 23:56:40 ideapad kernel: [  151.715980] 0xffffffff
   235  Jan  4 23:56:40 ideapad kernel: [  151.715982] 0x0
   236  Jan  4 23:56:40 ideapad kernel: [  151.715995] 0xffffffff
   237  Jan  4 23:56:40 ideapad kernel: [  151.720342] 0x0
   238  Jan  4 23:56:40 ideapad kernel: [  151.720347] 0x0
   239  Jan  4 23:56:40 ideapad kernel: [  151.720361] 0x0
   240  Jan  4 23:56:40 ideapad kernel: [  151.720365] 0x0
...
  8163  Jan  4 23:56:40 ideapad kernel: [  151.987049] 0x0
  8164  Jan  4 23:56:40 ideapad kernel: [  151.987061] 0x0
  8165  Jan  4 23:56:40 ideapad kernel: [  151.987063] 0x0
  8166  Jan  4 23:56:40 ideapad kernel: [  151.987075] 0x0


Mario
-- 
If her DNA was off by one percentage point, she'd be a dolphin.
                                -- Dr. Gregory House

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

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

* Re: 2.6.37-rc7: Regression: b43: crashes in hwrng_register()
  2011-01-04 23:06                                     ` Mario 'BitKoenig' Holbe
@ 2011-01-04 23:26                                       ` Larry Finger
  2011-01-04 23:35                                       ` Mario 'BitKoenig' Holbe
  2011-01-05  0:30                                       ` Herbert Xu
  2 siblings, 0 replies; 29+ messages in thread
From: Larry Finger @ 2011-01-04 23:26 UTC (permalink / raw)
  To: Mario 'BitKoenig' Holbe, Herbert Xu, Matt Mackall, LKML,
	Linux 

On 01/04/2011 05:06 PM, Mario 'BitKoenig' Holbe wrote:
> On Wed, Jan 05, 2011 at 09:42:38AM +1100, Herbert Xu wrote:
>> Can you please try this patch against vanilla to print out the
>> raw output of xstore?
> 
> # ps -ef | grep 'rng[d]'
> # cat /sys/devices/virtual/misc/hw_random/rng_available
> via 
> # hexdump -n 16 -C /dev/hwrng
> 00000000  00 ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|

This thread just keeps getting more and more interesting! :)

For reference, this is what I get for b43:

hexdump -n 16 -C /dev/hwrng
00000000  c7 87 ec 43 fa ac a8 c2  3b 0d a6 8f 3e 35 54 ee  |...C....;...>5T.|

Larry

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

* Re: 2.6.37-rc7: Regression: b43: crashes in hwrng_register()
  2011-01-04 23:06                                     ` Mario 'BitKoenig' Holbe
  2011-01-04 23:26                                       ` Larry Finger
@ 2011-01-04 23:35                                       ` Mario 'BitKoenig' Holbe
  2011-01-05  0:30                                       ` Herbert Xu
  2 siblings, 0 replies; 29+ messages in thread
From: Mario 'BitKoenig' Holbe @ 2011-01-04 23:35 UTC (permalink / raw)
  To: Herbert Xu, Larry Finger, Matt Mackall, LKML,
	Linux Crypto Mailing List <l

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

On Wed, Jan 05, 2011 at 12:06:44AM +0100, Mario 'BitKoenig' Holbe wrote:
> On Wed, Jan 05, 2011 at 09:42:38AM +1100, Herbert Xu wrote:
> > Can you please try this patch against vanilla to print out the
> > raw output of xstore?
> 00000000  00 ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|

Btw: the same with vanilla 2.6.37-rc7 and only the printk in xstore()
from your 2nd patch:

# hexdump -n 16 -C /dev/hwrng
00000000  2b f3 16 07 e8 57 1a a9  d2 3e 7f ad 0e 78 75 7f  |+....W...>...xu.|
00000010
# 


kern.log meanwhile (lines numbered):

     1  Jan  5 00:27:09 ideapad kernel: [  122.489475] 0x25ba3b2b
     2  Jan  5 00:27:09 ideapad kernel: [  122.489486] 0xe68ae2f3
     3  Jan  5 00:27:09 ideapad kernel: [  122.489489] 0x0
     4  Jan  5 00:27:09 ideapad kernel: [  122.489502] 0x75621016
     5  Jan  5 00:27:09 ideapad kernel: [  122.489505] 0x0
     6  Jan  5 00:27:09 ideapad kernel: [  122.489518] 0x727edc07
     7  Jan  5 00:27:09 ideapad kernel: [  122.489520] 0x0
     8  Jan  5 00:27:09 ideapad kernel: [  122.489534] 0x851b82e8
     9  Jan  5 00:27:09 ideapad kernel: [  122.491241] 0xfba49c57
    10  Jan  5 00:27:09 ideapad kernel: [  122.491245] 0x0
    11  Jan  5 00:27:09 ideapad kernel: [  122.491258] 0xc63eca1a
...
  8156  Jan  5 00:27:10 ideapad kernel: [  122.782215] 0x0
  8157  Jan  5 00:27:10 ideapad kernel: [  122.782228] 0xb736d99b
  8158  Jan  5 00:27:10 ideapad kernel: [  122.782230] 0x0
  8159  Jan  5 00:27:10 ideapad kernel: [  122.782243] 0x339211fd
  8160  Jan  5 00:27:10 ideapad kernel: [  122.782246] 0x0
  8161  Jan  5 00:27:10 ideapad kernel: [  122.782258] 0x12f898d1
  8162  Jan  5 00:27:10 ideapad kernel: [  122.782261] 0x0
  8163  Jan  5 00:27:10 ideapad kernel: [  122.782273] 0xc73fcdda


Mario
-- 
The question of whether a computer can think is no more interesting than
the question of whether a submarine can swim.          -- E. W. Dijkstra

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

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

* Re: 2.6.37-rc7: Regression: b43: crashes in hwrng_register()
  2011-01-04 22:42                                   ` Herbert Xu
  2011-01-04 23:06                                     ` Mario 'BitKoenig' Holbe
@ 2011-01-05  0:14                                     ` Larry Finger
  2011-01-05  0:19                                       ` Herbert Xu
  1 sibling, 1 reply; 29+ messages in thread
From: Larry Finger @ 2011-01-05  0:14 UTC (permalink / raw)
  To: Herbert Xu
  Cc: Mario 'BitKoenig' Holbe, Matt Mackall, LKML,
	Linux Crypto Mailing List, Harald Welte, Michal Ludvig

On 01/04/2011 04:42 PM, Herbert Xu wrote:
> On Tue, Jan 04, 2011 at 01:57:22PM +0100, Mario 'BitKoenig' Holbe wrote:
>>
>> # hexdump -n 512 -C /dev/hwrng
>> 00000000  00 ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
>> 00000010  ff ff ff ff ff ff ff 00  00 00 00 00 00 00 00 00  |................|
>> 00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
>> *
> 
> Weird.
> 
> Can you please try this patch against vanilla to print out the
> raw output of xstore?
> 
> diff --git a/drivers/char/hw_random/via-rng.c b/drivers/char/hw_random/via-rng.c
> index 794aacb..4408d4e 100644
> --- a/drivers/char/hw_random/via-rng.c
> +++ b/drivers/char/hw_random/via-rng.c
> @@ -24,6 +24,7 @@
>   * warranty of any kind, whether express or implied.
>   */
>  
> +#include <crypto/padlock.h>
>  #include <linux/module.h>
>  #include <linux/kernel.h>
>  #include <linux/hw_random.h>
> @@ -34,7 +35,6 @@
>  #include <asm/i387.h>
>  
>  
> -#define PFX	KBUILD_MODNAME ": "
>  
>  
>  enum {
> @@ -85,13 +85,16 @@ static inline u32 xstore(u32 *addr, u32 edx_in)
>  		:"D"(addr), "d"(edx_in));
>  
>  	irq_ts_restore(ts_state);
> +	printk(KERN_DEBUG "0x%x\n", *addr);
>  	return eax_out;
>  }
>  
>  static int via_rng_data_present(struct hwrng *rng, int wait)
>  {
> +	char buf[16 + PADLOCK_ALIGNMENT - STACK_ALIGN] __attribute__
> +		((aligned(STACK_ALIGN)));
> +	u32 *via_rng_datum = (u32 *)PTR_ALIGN(&buf[0], PADLOCK_ALIGNMENT);

If I didn't get lost in expanding all those macros, I think the above can end up
with what is essentially a negative value for the index of buf. Shouldn't the
right-hand side of the statement be

(u32 *)PTR_ALIGN(&buf[PADLOCK_ALIGNMENT], PADLOCK_ALIGNMENT);

That resolves to an index for buf from 0 to (PADLOCK_ALIGNMENT - 1).

Larry

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

* Re: 2.6.37-rc7: Regression: b43: crashes in hwrng_register()
  2011-01-05  0:14                                     ` 2.6.37-rc7: Regression: b43: crashes in hwrng_register() Larry Finger
@ 2011-01-05  0:19                                       ` Herbert Xu
  2011-01-05  1:38                                         ` Larry Finger
  0 siblings, 1 reply; 29+ messages in thread
From: Herbert Xu @ 2011-01-05  0:19 UTC (permalink / raw)
  To: Larry Finger
  Cc: Mario 'BitKoenig' Holbe, Matt Mackall, LKML,
	Linux Crypto Mailing List, Harald Welte, Michal Ludvig

On Tue, Jan 04, 2011 at 06:14:16PM -0600, Larry Finger wrote:
>
> If I didn't get lost in expanding all those macros, I think the above can end up
> with what is essentially a negative value for the index of buf. Shouldn't the
> right-hand side of the statement be
> 
> (u32 *)PTR_ALIGN(&buf[PADLOCK_ALIGNMENT], PADLOCK_ALIGNMENT);
> 
> That resolves to an index for buf from 0 to (PADLOCK_ALIGNMENT - 1).

PTR_ALIGN (and ALIGN) rounds up, not down.

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: 2.6.37-rc7: Regression: b43: crashes in hwrng_register()
  2011-01-04 23:06                                     ` Mario 'BitKoenig' Holbe
  2011-01-04 23:26                                       ` Larry Finger
  2011-01-04 23:35                                       ` Mario 'BitKoenig' Holbe
@ 2011-01-05  0:30                                       ` Herbert Xu
  2011-01-05  1:45                                         ` Mario 'BitKoenig' Holbe
  2011-01-05  3:52                                         ` Mario 'BitKoenig' Holbe
  2 siblings, 2 replies; 29+ messages in thread
From: Herbert Xu @ 2011-01-05  0:30 UTC (permalink / raw)
  To: Mario 'BitKoenig' Holbe, Larry Finger, Matt Mackall, LKML,
	Linux 

On Wed, Jan 05, 2011 at 12:06:44AM +0100, Mario 'BitKoenig' Holbe wrote:
> 
> kern.log meanwhile (lines numbered):
>      1  Jan  4 23:56:40 ideapad kernel: [  151.714225] 0x0
>      2  Jan  4 23:56:40 ideapad kernel: [  151.714236] 0xffffffff
>      3  Jan  4 23:56:40 ideapad kernel: [  151.714239] 0x0
>      4  Jan  4 23:56:40 ideapad kernel: [  151.714251] 0xffffffff

OK, so xstore really is producing crap.  Can you try this path
(also against vanilla) to print out some extra info?

diff --git a/drivers/char/hw_random/via-rng.c b/drivers/char/hw_random/via-rng.c
index 794aacb..d7ef7ac 100644
--- a/drivers/char/hw_random/via-rng.c
+++ b/drivers/char/hw_random/via-rng.c
@@ -24,6 +24,7 @@
  * warranty of any kind, whether express or implied.
  */
 
+#include <crypto/padlock.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/hw_random.h>
@@ -34,7 +35,6 @@
 #include <asm/i387.h>
 
 
-#define PFX	KBUILD_MODNAME ": "
 
 
 enum {
@@ -85,13 +85,16 @@ static inline u32 xstore(u32 *addr, u32 edx_in)
 		:"D"(addr), "d"(edx_in));
 
 	irq_ts_restore(ts_state);
+	printk(KERN_DEBUG "%p 0x%x 0x%x\n", addr, *addr, eax_out);
 	return eax_out;
 }
 
 static int via_rng_data_present(struct hwrng *rng, int wait)
 {
+	char buf[16 + PADLOCK_ALIGNMENT - STACK_ALIGN] __attribute__
+		((aligned(STACK_ALIGN)));
+	u32 *via_rng_datum = (u32 *)PTR_ALIGN(&buf[0], PADLOCK_ALIGNMENT);
 	u32 bytes_out;
-	u32 *via_rng_datum = (u32 *)(&rng->priv);
 	int i;
 
 	/* We choose the recommended 1-byte-per-instruction RNG rate,
@@ -115,6 +118,7 @@ static int via_rng_data_present(struct hwrng *rng, int wait)
 			break;
 		udelay(10);
 	}
+	rng->priv = *via_rng_datum;
 	return bytes_out ? 1 : 0;
 }
 
diff --git a/drivers/crypto/padlock-aes.c b/drivers/crypto/padlock-aes.c
index 2e992bc..2e56508 100644
--- a/drivers/crypto/padlock-aes.c
+++ b/drivers/crypto/padlock-aes.c
@@ -9,6 +9,7 @@
 
 #include <crypto/algapi.h>
 #include <crypto/aes.h>
+#include <crypto/padlock.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/types.h>
@@ -21,7 +22,6 @@
 #include <asm/byteorder.h>
 #include <asm/processor.h>
 #include <asm/i387.h>
-#include "padlock.h"
 
 /*
  * Number of data blocks actually fetched for each xcrypt insn.
diff --git a/drivers/crypto/padlock-sha.c b/drivers/crypto/padlock-sha.c
index d3a27e0..adf075b 100644
--- a/drivers/crypto/padlock-sha.c
+++ b/drivers/crypto/padlock-sha.c
@@ -13,6 +13,7 @@
  */
 
 #include <crypto/internal/hash.h>
+#include <crypto/padlock.h>
 #include <crypto/sha.h>
 #include <linux/err.h>
 #include <linux/module.h>
@@ -22,13 +23,6 @@
 #include <linux/kernel.h>
 #include <linux/scatterlist.h>
 #include <asm/i387.h>
-#include "padlock.h"
-
-#ifdef CONFIG_64BIT
-#define STACK_ALIGN 16
-#else
-#define STACK_ALIGN 4
-#endif
 
 struct padlock_sha_desc {
 	struct shash_desc fallback;
diff --git a/drivers/crypto/padlock.h b/drivers/crypto/padlock.h
deleted file mode 100644
index b728e45..0000000
--- a/drivers/crypto/padlock.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Driver for VIA PadLock
- *
- * Copyright (c) 2004 Michal Ludvig <michal@logix.cz>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option) 
- * any later version.
- *
- */
-
-#ifndef _CRYPTO_PADLOCK_H
-#define _CRYPTO_PADLOCK_H
-
-#define PADLOCK_ALIGNMENT 16
-
-#define PFX	"padlock: "
-
-#define PADLOCK_CRA_PRIORITY	300
-#define PADLOCK_COMPOSITE_PRIORITY 400
-
-#endif	/* _CRYPTO_PADLOCK_H */
diff --git a/include/crypto/padlock.h b/include/crypto/padlock.h
new file mode 100644
index 0000000..d2cfa2e
--- /dev/null
+++ b/include/crypto/padlock.h
@@ -0,0 +1,29 @@
+/*
+ * Driver for VIA PadLock
+ *
+ * Copyright (c) 2004 Michal Ludvig <michal@logix.cz>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option) 
+ * any later version.
+ *
+ */
+
+#ifndef _CRYPTO_PADLOCK_H
+#define _CRYPTO_PADLOCK_H
+
+#define PADLOCK_ALIGNMENT 16
+
+#define PFX	KBUILD_MODNAME ": "
+
+#define PADLOCK_CRA_PRIORITY	300
+#define PADLOCK_COMPOSITE_PRIORITY 400
+
+#ifdef CONFIG_64BIT
+#define STACK_ALIGN 16
+#else
+#define STACK_ALIGN 4
+#endif
+
+#endif	/* _CRYPTO_PADLOCK_H */

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: 2.6.37-rc7: Regression: b43: crashes in hwrng_register()
  2011-01-05  0:19                                       ` Herbert Xu
@ 2011-01-05  1:38                                         ` Larry Finger
  0 siblings, 0 replies; 29+ messages in thread
From: Larry Finger @ 2011-01-05  1:38 UTC (permalink / raw)
  To: Herbert Xu
  Cc: Mario 'BitKoenig' Holbe, Matt Mackall, LKML,
	Linux Crypto Mailing List, Harald Welte, Michal Ludvig

On 01/04/2011 06:19 PM, Herbert Xu wrote:
> 
> PTR_ALIGN (and ALIGN) rounds up, not down.

I see where I got lost in the macro expansions.

I'm still trying to understand the need for the __attribute__ on the definition
for buf.

Larry

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

* Re: 2.6.37-rc7: Regression: b43: crashes in hwrng_register()
  2011-01-05  0:30                                       ` Herbert Xu
@ 2011-01-05  1:45                                         ` Mario 'BitKoenig' Holbe
  2011-01-05  3:52                                         ` Mario 'BitKoenig' Holbe
  1 sibling, 0 replies; 29+ messages in thread
From: Mario 'BitKoenig' Holbe @ 2011-01-05  1:45 UTC (permalink / raw)
  To: Herbert Xu
  Cc: Larry Finger, Matt Mackall, LKML, Linux Crypto Mailing List,
	Harald Welte, Michal Ludvig

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

On Wed, Jan 05, 2011 at 11:30:20AM +1100, Herbert Xu wrote:
> OK, so xstore really is producing crap.  Can you try this path
> (also against vanilla) to print out some extra info?
> 
>  	irq_ts_restore(ts_state);
> +	printk(KERN_DEBUG "%p 0x%x 0x%x\n", addr, *addr, eax_out);
>  	return eax_out;

# dd if=/dev/hwrng bs=16 count=1 | hexdump -C
1+0 records in
1+0 records out
16 bytes (16 B) copied, 0,000288649 s, 55,4 kB/s
00000000  00 ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00000010
#                                                                                   

Jan  5 02:25:00 ideapad kernel: [  112.073759] f3cc3f38 0x0 0x8
Jan  5 02:25:00 ideapad kernel: [  112.073770] f3cc3f38 0xffffffff 0x8
Jan  5 02:25:00 ideapad kernel: [  112.073774] f3cc3f30 0x0 0x0
Jan  5 02:25:00 ideapad kernel: [  112.073788] f3cc3f38 0xffffffff 0x8
Jan  5 02:25:00 ideapad kernel: [  112.073791] f3cc3f30 0x0 0x0
Jan  5 02:25:00 ideapad kernel: [  112.073805] f3cc3f38 0xffffffff 0x8
Jan  5 02:25:00 ideapad kernel: [  112.073808] f3cc3f30 0x0 0x0
Jan  5 02:25:00 ideapad kernel: [  112.073821] f3cc3f38 0xffffffff 0x8
Jan  5 02:25:00 ideapad kernel: [  112.073825] f3cc3f30 0x0 0x0
Jan  5 02:25:00 ideapad kernel: [  112.073838] f3cc3f38 0xffffffff 0x8
Jan  5 02:25:00 ideapad kernel: [  112.073841] f3cc3f30 0x0 0x0
Jan  5 02:25:00 ideapad kernel: [  112.073855] f3cc3f38 0xffffffff 0x8
Jan  5 02:25:00 ideapad kernel: [  112.073858] f3cc3f30 0x0 0x0
Jan  5 02:25:00 ideapad kernel: [  112.073872] f3cc3f38 0xffffffff 0x8
Jan  5 02:25:00 ideapad kernel: [  112.073875] f3cc3f30 0x0 0x0
Jan  5 02:25:00 ideapad kernel: [  112.073888] f3cc3f38 0xffffffff 0x8
Jan  5 02:25:00 ideapad kernel: [  112.073892] f3cc3f30 0x0 0x0
Jan  5 02:25:00 ideapad kernel: [  112.073905] f3cc3f38 0xffffffff 0x8
Jan  5 02:25:00 ideapad kernel: [  112.073908] f3cc3f30 0x0 0x0
Jan  5 02:25:00 ideapad kernel: [  112.073922] f3cc3f38 0xffffffff 0x8
Jan  5 02:25:00 ideapad kernel: [  112.073925] f3cc3f30 0x0 0x0
Jan  5 02:25:00 ideapad kernel: [  112.073938] f3cc3f38 0xffffffff 0x8
Jan  5 02:25:00 ideapad kernel: [  112.073942] f3cc3f30 0x0 0x0
Jan  5 02:25:00 ideapad kernel: [  112.073955] f3cc3f38 0xffffffff 0x8
Jan  5 02:25:00 ideapad kernel: [  112.073959] f3cc3f30 0x0 0x0
Jan  5 02:25:00 ideapad kernel: [  112.073972] f3cc3f38 0xffffffff 0x8
Jan  5 02:25:00 ideapad kernel: [  112.073975] f3cc3f30 0x0 0x0
Jan  5 02:25:00 ideapad kernel: [  112.073989] f3cc3f38 0xffffffff 0x8
Jan  5 02:25:00 ideapad kernel: [  112.073992] f3cc3f30 0x0 0x0
Jan  5 02:25:00 ideapad kernel: [  112.074005] f3cc3f38 0xffffffff 0x8


Mario
-- 
Oh Du mein Koenig ... Eine Netzgroesse schrieb mal sinngemaess:
Du musst es so lesen wie ich es meine, nicht so wie ich es schreibe.
Ich meine es natuerlich so, wie Du es schreibst 8--)
                              -- O.G. Schwenk in de.comm.chatsystems

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

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

* Re: 2.6.37-rc7: Regression: b43: crashes in hwrng_register()
  2011-01-05  0:30                                       ` Herbert Xu
  2011-01-05  1:45                                         ` Mario 'BitKoenig' Holbe
@ 2011-01-05  3:52                                         ` Mario 'BitKoenig' Holbe
  2011-01-05  5:47                                           ` Herbert Xu
  1 sibling, 1 reply; 29+ messages in thread
From: Mario 'BitKoenig' Holbe @ 2011-01-05  3:52 UTC (permalink / raw)
  To: Herbert Xu
  Cc: Larry Finger, Matt Mackall, LKML, Linux Crypto Mailing List,
	Harald Welte, Michal Ludvig

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

On Wed, Jan 05, 2011 at 11:30:20AM +1100, Herbert Xu wrote:
> OK, so xstore really is producing crap.  Can you try this path
> (also against vanilla) to print out some extra info?

All right, here is what happens...

On top of your 3rd patch:

--- linux-source-2.6.37-rc7/drivers/char/hw_random/via-rng.c.hxu3	2011-01-05 04:13:09.452322117 +0100
+++ linux-source-2.6.37-rc7/drivers/char/hw_random/via-rng.c	2011-01-05 03:59:33.169316276 +0100
@@ -97,6 +97,10 @@ static int via_rng_data_present(struct h
 	u32 bytes_out;
 	int i;
 
+	printk(KERN_DEBUG "buf=%p + %zu, via_rng_datum=%p\n",
+			buf, sizeof(buf), via_rng_datum);
+
+
 	/* We choose the recommended 1-byte-per-instruction RNG rate,
 	 * for greater randomness at the expense of speed.  Larger
 	 * values 2, 4, or 8 bytes-per-instruction yield greater

gives:

[  103.276337] buf=f6e23f28 + 28, via_rng_datum=f6e23f30
[  103.276351] f6e23f38 0x0 0x8
[  103.276371] buf=f6e23f28 + 28, via_rng_datum=f6e23f30
[  103.276380] f6e23f38 0xffffffff 0x8
...

According to the VIA PadLock Programming Guide, XSTORE increments EDI by
the number of bytes stored.
This did obviously not matter as long as the buffer was "sufficiently
distant", but now you have the buffer close on the stack and I believe,
the optimizer crops up, hence the EDI increment begins to matter.

IMHO EDI (and EDX - for completeness :)) should be put on the asm
clobber-list, but if I try to do it, I always get:
error: can't find a register in class 'DIREG' while reloading 'asm'
error: 'asm' operand has impossible constraints

So... I have the reason - solution is up to you :)

Btw: the 8 bytes increment (as well as the 8 in EAX 4:0) proves that
XSTOR indeed writes more than 32bit :)


g'nite
   Mario
-- 
The only thing to be scared of, son, is tomorrow.
I don't live for tomorrow. Never saw the fun in it.
                       -- Denny Crane, Boston Legal

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

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

* Re: 2.6.37-rc7: Regression: b43: crashes in hwrng_register()
  2011-01-05  3:52                                         ` Mario 'BitKoenig' Holbe
@ 2011-01-05  5:47                                           ` Herbert Xu
  2011-01-05 13:16                                             ` Mario 'BitKoenig' Holbe
  0 siblings, 1 reply; 29+ messages in thread
From: Herbert Xu @ 2011-01-05  5:47 UTC (permalink / raw)
  To: Mario 'BitKoenig' Holbe, Larry Finger, Matt Mackall, LKML,
	Linux 

On Wed, Jan 05, 2011 at 04:52:22AM +0100, Mario 'BitKoenig' Holbe wrote:
>
> According to the VIA PadLock Programming Guide, XSTORE increments EDI by
> the number of bytes stored.
> This did obviously not matter as long as the buffer was "sufficiently
> distant", but now you have the buffer close on the stack and I believe,
> the optimizer crops up, hence the EDI increment begins to matter.

Interesting.  So your compiler was producing incorrect output.
What version of gcc were you using?

Please attach the assembly output of the function in question.

Thanks!
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: 2.6.37-rc7: Regression: b43: crashes in hwrng_register()
  2011-01-05  5:47                                           ` Herbert Xu
@ 2011-01-05 13:16                                             ` Mario 'BitKoenig' Holbe
  2011-01-06  6:12                                               ` Herbert Xu
       [not found]                                               ` <20110106061241.GA18939@gondor.apana.org.au>
  0 siblings, 2 replies; 29+ messages in thread
From: Mario 'BitKoenig' Holbe @ 2011-01-05 13:16 UTC (permalink / raw)
  To: Herbert Xu
  Cc: Larry Finger, Matt Mackall, LKML, Linux Crypto Mailing List,
	Harald Welte, Michal Ludvig


[-- Attachment #1.1: Type: text/plain, Size: 2952 bytes --]

On Wed, Jan 05, 2011 at 04:47:35PM +1100, Herbert Xu wrote:
> On Wed, Jan 05, 2011 at 04:52:22AM +0100, Mario 'BitKoenig' Holbe wrote:
> > According to the VIA PadLock Programming Guide, XSTORE increments EDI by
> > the number of bytes stored.
> > This did obviously not matter as long as the buffer was "sufficiently
> > distant", but now you have the buffer close on the stack and I believe,
> > the optimizer crops up, hence the EDI increment begins to matter.
> Interesting.  So your compiler was producing incorrect output.

Why incorrect? How should the compiler know that EDI gets modified?
It's listed as XSTORE input only.

> What version of gcc were you using?

gcc version 4.4.5 (Debian 4.4.5-10) 

> Please attach the assembly output of the function in question.

attached. I hope I got the gcc call right. However, I prefer the objdump
output anyways, so this one is attached as well.

As you can see (from both, maybe less from the one, more from the
other), it is as I supposed it to be: the optimizer uses EDI to store
via_rng_datum - reasonable, since EDI is a required input for the asm()
directive anyways. And since it doesn't know EDI gets modified, it just
continues using it as via_rng_datum afterwards.

Btw: this is also the reason why it did work before: before, &rng->priv
was never used again in a close-enough (and static enough) context, so
it didn't matter whether EDI (which surely was used as &rng->priv) was
clobbered or not.

The IMHO best solution would be to tell the compiler that EDI gets
clobbered: attached via-rng1-preferred.patch to apply on top of your
first patch. However, as I already said, the compiler starts whining
with either of both inputs on the clobber-list (don't really know why it
cries for edx, but well...).

The overkill solution is to preserve EDI manually: attached
via-rng1-overkill.patch to apply on top of your first patch.
And... yes, this works, really :)

As I already said in my mail before: IMHO, for completeness, EDX should
be preserved as well: the PadLock Quick Reference states the upper 30
bits of EDX will be zeroed by XSTORE, the VIA PadLock Programming Guide
states they may be zeroed.
This does currently not really matter, since a) VIA_RNG_CHUNK_1 (0x03)
is quite zero in the upper 30 bits, and b) the XSTORE quality factor is
only defined with 2 bits.
Though it's hard to believe this could ever change, I could imagine
future code that, for example, tries to balance quality/speed, and
chooses different values for EDX (and overloads the upper 30 bits for
some additional internal information) and after xstore() behaves
different based on the value chosen before. Then, it would matter.


Mario
-- 
It is practically impossible to teach good programming style to students
that have had prior exposure to BASIC: as potential programmers they are
mentally mutilated beyond hope of regeneration.  -- Dijkstra

[-- Attachment #1.2: via-rng.S.bz2 --]
[-- Type: application/octet-stream, Size: 33188 bytes --]

[-- Attachment #1.3: via-rng.o.objdump.bz2 --]
[-- Type: application/octet-stream, Size: 4078 bytes --]

[-- Attachment #1.4: via-rng1-preferred.patch --]
[-- Type: text/x-diff, Size: 483 bytes --]

--- linux-source-2.6.37-rc7/drivers/char/hw_random/via-rng.c.hxu1	2011-01-05 11:32:12.508274625 +0100
+++ linux-source-2.6.37-rc7/drivers/char/hw_random/via-rng.c	2011-01-05 12:57:19.712085325 +0100
@@ -82,7 +82,8 @@ static inline u32 xstore(u32 *addr, u32
 
 	asm(".byte 0x0F,0xA7,0xC0 /* xstore %%edi (addr=%0) */"
 		:"=m"(*addr), "=a"(eax_out)
-		:"D"(addr), "d"(edx_in));
+		:"D"(addr), "d"(edx_in)
+		:"edi", "edx");
 
 	irq_ts_restore(ts_state);
 	return eax_out;

[-- Attachment #1.5: via-rng1-overkill.patch --]
[-- Type: text/x-diff, Size: 525 bytes --]

--- linux-source-2.6.37-rc7/drivers/char/hw_random/via-rng.c.hxu1	2011-01-05 11:32:12.508274625 +0100
+++ linux-source-2.6.37-rc7/drivers/char/hw_random/via-rng.c	2011-01-05 12:45:43.459208713 +0100
@@ -80,7 +80,9 @@ static inline u32 xstore(u32 *addr, u32
 
 	ts_state = irq_ts_save();
 
-	asm(".byte 0x0F,0xA7,0xC0 /* xstore %%edi (addr=%0) */"
+	asm("pushl %%edi\n"
+	    ".byte 0x0F,0xA7,0xC0 /* xstore %%edi (addr=%0) */\n"
+	    "popl %%edi\n"
 		:"=m"(*addr), "=a"(eax_out)
 		:"D"(addr), "d"(edx_in));
 

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

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

* Re: 2.6.37-rc7: Regression: b43: crashes in hwrng_register()
  2011-01-05 13:16                                             ` Mario 'BitKoenig' Holbe
@ 2011-01-06  6:12                                               ` Herbert Xu
       [not found]                                               ` <20110106061241.GA18939@gondor.apana.org.au>
  1 sibling, 0 replies; 29+ messages in thread
From: Herbert Xu @ 2011-01-06  6:12 UTC (permalink / raw)
  To: Mario 'BitKoenig' Holbe, Larry Finger, Matt Mackall, LKML,
	Linux 

On Wed, Jan 05, 2011 at 02:16:22PM +0100, Mario 'BitKoenig' Holbe wrote:
>
> attached. I hope I got the gcc call right. However, I prefer the objdump
> output anyways, so this one is attached as well.

I see what you mean now.

Please let me know if this patch (still against vanilla) helps.

diff --git a/drivers/char/hw_random/via-rng.c b/drivers/char/hw_random/via-rng.c
index 794aacb..6788bbc 100644
--- a/drivers/char/hw_random/via-rng.c
+++ b/drivers/char/hw_random/via-rng.c
@@ -24,6 +24,7 @@
  * warranty of any kind, whether express or implied.
  */
 
+#include <crypto/padlock.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/hw_random.h>
@@ -34,7 +35,6 @@
 #include <asm/i387.h>
 
 
-#define PFX	KBUILD_MODNAME ": "
 
 
 enum {
@@ -81,8 +81,13 @@ static inline u32 xstore(u32 *addr, u32 edx_in)
 	ts_state = irq_ts_save();
 
 	asm(".byte 0x0F,0xA7,0xC0 /* xstore %%edi (addr=%0) */"
-		:"=m"(*addr), "=a"(eax_out)
-		:"D"(addr), "d"(edx_in));
+		: "=m" (*addr), "=a" (eax_out), "+D" (addr)
+		: "d" (edx_in)
+#ifdef CONFIG_64BIT
+		: "%rcx");
+#else
+		: "%ecx");
+#endif
 
 	irq_ts_restore(ts_state);
 	return eax_out;
@@ -90,8 +95,10 @@ static inline u32 xstore(u32 *addr, u32 edx_in)
 
 static int via_rng_data_present(struct hwrng *rng, int wait)
 {
+	char buf[16 + PADLOCK_ALIGNMENT - STACK_ALIGN] __attribute__
+		((aligned(STACK_ALIGN)));
+	u32 *via_rng_datum = (u32 *)PTR_ALIGN(&buf[0], PADLOCK_ALIGNMENT);
 	u32 bytes_out;
-	u32 *via_rng_datum = (u32 *)(&rng->priv);
 	int i;
 
 	/* We choose the recommended 1-byte-per-instruction RNG rate,
@@ -115,6 +122,7 @@ static int via_rng_data_present(struct hwrng *rng, int wait)
 			break;
 		udelay(10);
 	}
+	rng->priv = *via_rng_datum;
 	return bytes_out ? 1 : 0;
 }
 
diff --git a/drivers/crypto/padlock-aes.c b/drivers/crypto/padlock-aes.c
index 2e992bc..2e56508 100644
--- a/drivers/crypto/padlock-aes.c
+++ b/drivers/crypto/padlock-aes.c
@@ -9,6 +9,7 @@
 
 #include <crypto/algapi.h>
 #include <crypto/aes.h>
+#include <crypto/padlock.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/types.h>
@@ -21,7 +22,6 @@
 #include <asm/byteorder.h>
 #include <asm/processor.h>
 #include <asm/i387.h>
-#include "padlock.h"
 
 /*
  * Number of data blocks actually fetched for each xcrypt insn.
diff --git a/drivers/crypto/padlock-sha.c b/drivers/crypto/padlock-sha.c
index d3a27e0..adf075b 100644
--- a/drivers/crypto/padlock-sha.c
+++ b/drivers/crypto/padlock-sha.c
@@ -13,6 +13,7 @@
  */
 
 #include <crypto/internal/hash.h>
+#include <crypto/padlock.h>
 #include <crypto/sha.h>
 #include <linux/err.h>
 #include <linux/module.h>
@@ -22,13 +23,6 @@
 #include <linux/kernel.h>
 #include <linux/scatterlist.h>
 #include <asm/i387.h>
-#include "padlock.h"
-
-#ifdef CONFIG_64BIT
-#define STACK_ALIGN 16
-#else
-#define STACK_ALIGN 4
-#endif
 
 struct padlock_sha_desc {
 	struct shash_desc fallback;
diff --git a/drivers/crypto/padlock.h b/drivers/crypto/padlock.h
deleted file mode 100644
index b728e45..0000000
--- a/drivers/crypto/padlock.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Driver for VIA PadLock
- *
- * Copyright (c) 2004 Michal Ludvig <michal@logix.cz>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option) 
- * any later version.
- *
- */
-
-#ifndef _CRYPTO_PADLOCK_H
-#define _CRYPTO_PADLOCK_H
-
-#define PADLOCK_ALIGNMENT 16
-
-#define PFX	"padlock: "
-
-#define PADLOCK_CRA_PRIORITY	300
-#define PADLOCK_COMPOSITE_PRIORITY 400
-
-#endif	/* _CRYPTO_PADLOCK_H */
diff --git a/include/crypto/padlock.h b/include/crypto/padlock.h
new file mode 100644
index 0000000..d2cfa2e
--- /dev/null
+++ b/include/crypto/padlock.h
@@ -0,0 +1,29 @@
+/*
+ * Driver for VIA PadLock
+ *
+ * Copyright (c) 2004 Michal Ludvig <michal@logix.cz>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option) 
+ * any later version.
+ *
+ */
+
+#ifndef _CRYPTO_PADLOCK_H
+#define _CRYPTO_PADLOCK_H
+
+#define PADLOCK_ALIGNMENT 16
+
+#define PFX	KBUILD_MODNAME ": "
+
+#define PADLOCK_CRA_PRIORITY	300
+#define PADLOCK_COMPOSITE_PRIORITY 400
+
+#ifdef CONFIG_64BIT
+#define STACK_ALIGN 16
+#else
+#define STACK_ALIGN 4
+#endif
+
+#endif	/* _CRYPTO_PADLOCK_H */

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: 2.6.37-rc7: Regression: b43: crashes in hwrng_register()
       [not found]                                               ` <20110106061241.GA18939@gondor.apana.org.au>
@ 2011-01-06 13:15                                                 ` Mario 'BitKoenig' Holbe
  2011-01-06 13:35                                                   ` Herbert Xu
  0 siblings, 1 reply; 29+ messages in thread
From: Mario 'BitKoenig' Holbe @ 2011-01-06 13:15 UTC (permalink / raw)
  To: Herbert Xu
  Cc: Larry Finger, Matt Mackall, LKML, Linux Crypto Mailing List,
	Harald Welte, Michal Ludvig


[-- Attachment #1.1: Type: text/plain, Size: 1278 bytes --]

Hello Herbert,

On Thu, Jan 06, 2011 at 05:12:41PM +1100, Herbert Xu wrote:
> On Wed, Jan 05, 2011 at 02:16:22PM +0100, Mario 'BitKoenig' Holbe wrote:
> > attached. I hope I got the gcc call right. However, I prefer the objdump
> > output anyways, so this one is attached as well.
> I see what you mean now.
> Please let me know if this patch (still against vanilla) helps.

The patch helps. No crashes, meaningful random data - perfect.
I still have 2 small annotations...

1. Having ECX on the clobber-list is not really necessary.
XSTORE doesn't touch ECX at all.
REP XSTORE would touch it, but for this ECX would be an input anyways.

2. Would you mind doing the same for EDX as you did for EDI?
This doesn't really change anything currently, but will probably help
avoiding a debug-session like ours somewhere in the future :)

A patch that does both is attached - to apply on top of your patch, if
you like. I tested this patch - it passed all my tests: no crashes,
meaningful random data.


Thanks for your help & regards
   Mario
-- 
It is a capital mistake to theorize before one has data.
Insensibly one begins to twist facts to suit theories instead of theories
to suit facts.                   -- Sherlock Holmes by Arthur Conan Doyle

[-- Attachment #1.2: via-rng4-edx+unclobber.patch --]
[-- Type: text/x-diff, Size: 564 bytes --]

--- linux-source-2.6.37-rc7/drivers/char/hw_random/via-rng.c.hxu4	2011-01-06 09:40:44.879334924 +0100
+++ linux-source-2.6.37-rc7/drivers/char/hw_random/via-rng.c	2011-01-06 13:07:25.031181409 +0100
@@ -81,13 +81,7 @@
 	ts_state = irq_ts_save();
 
 	asm(".byte 0x0F,0xA7,0xC0 /* xstore %%edi (addr=%0) */"
-		: "=m" (*addr), "=a" (eax_out), "+D" (addr)
-		: "d" (edx_in)
-#ifdef CONFIG_64BIT
-		: "%rcx");
-#else
-		: "%ecx");
-#endif
+		: "=m" (*addr), "=a" (eax_out), "+D" (addr), "+d" (edx_in));
 
 	irq_ts_restore(ts_state);
 	return eax_out;

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

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

* Re: 2.6.37-rc7: Regression: b43: crashes in hwrng_register()
  2011-01-06 13:15                                                 ` Mario 'BitKoenig' Holbe
@ 2011-01-06 13:35                                                   ` Herbert Xu
  2011-01-06 13:56                                                     ` Larry Finger
  2011-01-06 14:42                                                     ` Mario 'BitKoenig' Holbe
  0 siblings, 2 replies; 29+ messages in thread
From: Herbert Xu @ 2011-01-06 13:35 UTC (permalink / raw)
  To: Mario 'BitKoenig' Holbe, Larry Finger, Matt Mackall, LKML,
	Linux 

On Thu, Jan 06, 2011 at 02:15:16PM +0100, Mario 'BitKoenig' Holbe wrote:
>
> The patch helps. No crashes, meaningful random data - perfect.
> I still have 2 small annotations...

Thanks for testing!

> 1. Having ECX on the clobber-list is not really necessary.
> XSTORE doesn't touch ECX at all.
> REP XSTORE would touch it, but for this ECX would be an input anyways.

The documentation wasn't clear whether ECX would be updated without
the REP prefix so I included it to be on the safe side.  Unfortunately
my only VIA machine is on another continent at the moment so I can't
test it myself.  Can you verify that ECX isn't changed without the
REP prefix?

> 2. Would you mind doing the same for EDX as you did for EDI?
> This doesn't really change anything currently, but will probably help
> avoiding a debug-session like ours somewhere in the future :)

According to my documentation EDX isn't be modified (nor would it
make sense as it would break REP XSTORE).  Are you seeing anything
different?

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: 2.6.37-rc7: Regression: b43: crashes in hwrng_register()
  2011-01-06 13:35                                                   ` Herbert Xu
@ 2011-01-06 13:56                                                     ` Larry Finger
  2011-01-06 14:42                                                     ` Mario 'BitKoenig' Holbe
  1 sibling, 0 replies; 29+ messages in thread
From: Larry Finger @ 2011-01-06 13:56 UTC (permalink / raw)
  To: Herbert Xu
  Cc: Mario 'BitKoenig' Holbe, Matt Mackall, LKML,
	Linux Crypto Mailing List, Harald Welte, Michal Ludvig

On 01/06/2011 07:35 AM, Herbert Xu wrote:
> On Thu, Jan 06, 2011 at 02:15:16PM +0100, Mario 'BitKoenig' Holbe wrote:
>>
>> The patch helps. No crashes, meaningful random data - perfect.
>> I still have 2 small annotations...
> 
> Thanks for testing!
> 
>> 1. Having ECX on the clobber-list is not really necessary.
>> XSTORE doesn't touch ECX at all.
>> REP XSTORE would touch it, but for this ECX would be an input anyways.
> 
> The documentation wasn't clear whether ECX would be updated without
> the REP prefix so I included it to be on the safe side.  Unfortunately
> my only VIA machine is on another continent at the moment so I can't
> test it myself.  Can you verify that ECX isn't changed without the
> REP prefix?
> 
>> 2. Would you mind doing the same for EDX as you did for EDI?
>> This doesn't really change anything currently, but will probably help
>> avoiding a debug-session like ours somewhere in the future :)
> 
> According to my documentation EDX isn't be modified (nor would it
> make sense as it would break REP XSTORE).  Are you seeing anything
> different?

As an interested observer, I think this routine needs some really detailed comments.

Larry

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

* Re: 2.6.37-rc7: Regression: b43: crashes in hwrng_register()
  2011-01-06 13:35                                                   ` Herbert Xu
  2011-01-06 13:56                                                     ` Larry Finger
@ 2011-01-06 14:42                                                     ` Mario 'BitKoenig' Holbe
  2011-01-07  3:49                                                       ` Herbert Xu
  1 sibling, 1 reply; 29+ messages in thread
From: Mario 'BitKoenig' Holbe @ 2011-01-06 14:42 UTC (permalink / raw)
  To: Herbert Xu
  Cc: Larry Finger, Matt Mackall, LKML, Linux Crypto Mailing List,
	Harald Welte, Michal Ludvig


[-- Attachment #1.1: Type: text/plain, Size: 1887 bytes --]

On Fri, Jan 07, 2011 at 12:35:41AM +1100, Herbert Xu wrote:
> On Thu, Jan 06, 2011 at 02:15:16PM +0100, Mario 'BitKoenig' Holbe wrote:
> > 1. Having ECX on the clobber-list is not really necessary.
> > XSTORE doesn't touch ECX at all.
> > REP XSTORE would touch it, but for this ECX would be an input anyways.
> 
> The documentation wasn't clear whether ECX would be updated without
> the REP prefix so I included it to be on the safe side.  Unfortunately
> my only VIA machine is on another continent at the moment so I can't
> test it myself.  Can you verify that ECX isn't changed without the
> REP prefix?

session-log (including small test case) attached: ECX is not changed.

> > 2. Would you mind doing the same for EDX as you did for EDI?
> According to my documentation EDX isn't be modified (nor would it
> make sense as it would break REP XSTORE).  Are you seeing anything
> different?

http://linux.via.com.tw/support/beginDownload.action?eleid=181&fid=261
VIA PadLock Programming Guide, v1.66, 4th August 2005
2.1 XSTORE Instructions (page 9)
RNG Quality Factor: EDX
[...] Only the lower two bits of EDX are meaningful; the upper 30 bits
are ignored by the instruction and may be set to zero.
                                   ^^^^^^^^^^^^^^^^^^

http://hackipedia.org/Hardware/CPU/x86/chip,%20VIA/nano/Padlock,%20quick%20reference%20v0.95%20(July%2025th,%202008).pdf
PadLock Quick Reference, v0.95, 25th July 2008
RANDOM NUMBER GENERATION (page 3)
Register Usage: Output
EDX Bits 0:1 are unchanged, all higher order bits are zero.
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

See the attached session-log as well: those EDX bits are indeed zeroed.


Btw: I believe both documents are quite clear regarding ECX for XSTORE.


Mario
-- 
User sind wie ideale Gase - sie verteilen sich gleichmaessig ueber alle Platten

[-- Attachment #1.2: via-rng-test.out --]
[-- Type: text/plain, Size: 1042 bytes --]

holbe@ideapad ~ % cat via-rng-test.c
#include <stdio.h>
#include <string.h>

static inline unsigned long xstore(unsigned long *addr, unsigned long edx)
{
	unsigned long eax_out;
	unsigned long ecx = 0xaa55aa55;
	int ts_state;

	printf("ecx: %08lx\tedx: %08lx\tedi: %p\n", ecx, edx, addr);

	asm(".byte 0x0F,0xA7,0xC0 /* xstore %%edi (addr=%0) */"
		: "=m" (*addr), "=a" (eax_out), "+D" (addr), "+d" (edx), "+c" (ecx));

	printf("ecx: %08lx\tedx: %08lx\tedi: %p\n", ecx, edx, addr);

	return eax_out;
}

int main(void) {
	unsigned long addr[8];

	memset(addr, 0, sizeof(addr));

	printf("%p: %08lx\n", addr, *(unsigned long *)addr);
	xstore(addr, 0xffffff03); /* 8 rand bits, 32 stored bits */
	printf("%p: %08lx\n", addr, *(unsigned long *)addr);

	return 0;
}
holbe@ideapad ~ % gcc -o via-rng-test via-rng-test.c
holbe@ideapad ~ % ./via-rng-test
0xbff09d40: 00000000
ecx: aa55aa55   edx: ffffff03   edi: 0xbff09d40
ecx: aa55aa55   edx: 00000003   edi: 0xbff09d48
0xbff09d40: 339d4525
holbe@ideapad ~ % 

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

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

* Re: 2.6.37-rc7: Regression: b43: crashes in hwrng_register()
  2011-01-06 14:42                                                     ` Mario 'BitKoenig' Holbe
@ 2011-01-07  3:49                                                       ` Herbert Xu
  2011-01-07  3:54                                                         ` crypto: padlock - Move padlock.h into include/crypto Herbert Xu
  0 siblings, 1 reply; 29+ messages in thread
From: Herbert Xu @ 2011-01-07  3:49 UTC (permalink / raw)
  To: Mario 'BitKoenig' Holbe, Larry Finger, Matt Mackall, LKML,
	Linux 

On Thu, Jan 06, 2011 at 03:42:55PM +0100, Mario 'BitKoenig' Holbe wrote:
>
> holbe@ideapad ~ % gcc -o via-rng-test via-rng-test.c
> holbe@ideapad ~ % ./via-rng-test
> 0xbff09d40: 00000000
> ecx: aa55aa55   edx: ffffff03   edi: 0xbff09d40
> ecx: aa55aa55   edx: 00000003   edi: 0xbff09d48
> 0xbff09d40: 339d4525
> holbe@ideapad ~ % 

Thanks, I've applied this patch:

commit 0735ac1f2551d9f9d356126aaf3b1110150918e6
Author: Herbert Xu <herbert@gondor.apana.org.au>
Date:   Fri Jan 7 14:48:57 2011 +1100

    hwrng: via_rng - Fix asm constraints
    
    The inline asm to invoke xstore did not specify the constraints
    correctly.  In particular, dx/di should have been marked as output
    registers as well as input as they're modified by xstore.
    
    Thanks to Mario Holbe for creating this patch and testing it.
    
    Tested-by: Mario 'BitKoenig' Holbe <Mario.Holbe@TU-Ilmenau.DE>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

diff --git a/drivers/char/hw_random/via-rng.c b/drivers/char/hw_random/via-rng.c
index 794aacb..7f86666 100644
--- a/drivers/char/hw_random/via-rng.c
+++ b/drivers/char/hw_random/via-rng.c
@@ -81,8 +81,7 @@ static inline u32 xstore(u32 *addr, u32 edx_in)
 	ts_state = irq_ts_save();
 
 	asm(".byte 0x0F,0xA7,0xC0 /* xstore %%edi (addr=%0) */"
-		:"=m"(*addr), "=a"(eax_out)
-		:"D"(addr), "d"(edx_in));
+		: "=m" (*addr), "=a" (eax_out), "+d" (edx_in), "+D" (addr));
 
 	irq_ts_restore(ts_state);
 	return eax_out;

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* crypto: padlock - Move padlock.h into include/crypto
  2011-01-07  3:49                                                       ` Herbert Xu
@ 2011-01-07  3:54                                                         ` Herbert Xu
  2011-01-07  3:55                                                           ` hwrng: via_rng - Fix memory scribbling on some CPUs Herbert Xu
  0 siblings, 1 reply; 29+ messages in thread
From: Herbert Xu @ 2011-01-07  3:54 UTC (permalink / raw)
  To: Mario 'BitKoenig' Holbe, Larry Finger, Matt Mackall, LKML,
	Linux 

On Fri, Jan 07, 2011 at 02:49:48PM +1100, Herbert Xu wrote:
>
> commit 0735ac1f2551d9f9d356126aaf3b1110150918e6
> Author: Herbert Xu <herbert@gondor.apana.org.au>
> Date:   Fri Jan 7 14:48:57 2011 +1100

Here are the other patches to fix this problem:

commit 21493088733e6e09dac6f54595a1b6b8ab1e68fd
Author: Herbert Xu <herbert@gondor.apana.org.au>
Date:   Fri Jan 7 14:52:00 2011 +1100

    crypto: padlock - Move padlock.h into include/crypto
    
    This patch moves padlock.h from drivers/crypto into include/crypto
    so that it may be used by the via-rng driver.
    
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

diff --git a/drivers/crypto/padlock-aes.c b/drivers/crypto/padlock-aes.c
index 2e992bc..2e56508 100644
--- a/drivers/crypto/padlock-aes.c
+++ b/drivers/crypto/padlock-aes.c
@@ -9,6 +9,7 @@
 
 #include <crypto/algapi.h>
 #include <crypto/aes.h>
+#include <crypto/padlock.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/types.h>
@@ -21,7 +22,6 @@
 #include <asm/byteorder.h>
 #include <asm/processor.h>
 #include <asm/i387.h>
-#include "padlock.h"
 
 /*
  * Number of data blocks actually fetched for each xcrypt insn.
diff --git a/drivers/crypto/padlock-sha.c b/drivers/crypto/padlock-sha.c
index d3a27e0..adf075b 100644
--- a/drivers/crypto/padlock-sha.c
+++ b/drivers/crypto/padlock-sha.c
@@ -13,6 +13,7 @@
  */
 
 #include <crypto/internal/hash.h>
+#include <crypto/padlock.h>
 #include <crypto/sha.h>
 #include <linux/err.h>
 #include <linux/module.h>
@@ -22,13 +23,6 @@
 #include <linux/kernel.h>
 #include <linux/scatterlist.h>
 #include <asm/i387.h>
-#include "padlock.h"
-
-#ifdef CONFIG_64BIT
-#define STACK_ALIGN 16
-#else
-#define STACK_ALIGN 4
-#endif
 
 struct padlock_sha_desc {
 	struct shash_desc fallback;
diff --git a/drivers/crypto/padlock.h b/drivers/crypto/padlock.h
deleted file mode 100644
index b728e45..0000000
--- a/drivers/crypto/padlock.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Driver for VIA PadLock
- *
- * Copyright (c) 2004 Michal Ludvig <michal@logix.cz>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option) 
- * any later version.
- *
- */
-
-#ifndef _CRYPTO_PADLOCK_H
-#define _CRYPTO_PADLOCK_H
-
-#define PADLOCK_ALIGNMENT 16
-
-#define PFX	"padlock: "
-
-#define PADLOCK_CRA_PRIORITY	300
-#define PADLOCK_COMPOSITE_PRIORITY 400
-
-#endif	/* _CRYPTO_PADLOCK_H */
diff --git a/include/crypto/padlock.h b/include/crypto/padlock.h
new file mode 100644
index 0000000..d2cfa2e
--- /dev/null
+++ b/include/crypto/padlock.h
@@ -0,0 +1,29 @@
+/*
+ * Driver for VIA PadLock
+ *
+ * Copyright (c) 2004 Michal Ludvig <michal@logix.cz>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option) 
+ * any later version.
+ *
+ */
+
+#ifndef _CRYPTO_PADLOCK_H
+#define _CRYPTO_PADLOCK_H
+
+#define PADLOCK_ALIGNMENT 16
+
+#define PFX	KBUILD_MODNAME ": "
+
+#define PADLOCK_CRA_PRIORITY	300
+#define PADLOCK_COMPOSITE_PRIORITY 400
+
+#ifdef CONFIG_64BIT
+#define STACK_ALIGN 16
+#else
+#define STACK_ALIGN 4
+#endif
+
+#endif	/* _CRYPTO_PADLOCK_H */

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* hwrng: via_rng - Fix memory scribbling on some CPUs
  2011-01-07  3:54                                                         ` crypto: padlock - Move padlock.h into include/crypto Herbert Xu
@ 2011-01-07  3:55                                                           ` Herbert Xu
  0 siblings, 0 replies; 29+ messages in thread
From: Herbert Xu @ 2011-01-07  3:55 UTC (permalink / raw)
  To: Mario 'BitKoenig' Holbe, Larry Finger, Matt Mackall, LKML,
	Linux 

commit 55db8387a5e8d07407f0b7c6b2526417a2bc6243
Author: Herbert Xu <herbert@gondor.apana.org.au>
Date:   Fri Jan 7 14:55:06 2011 +1100

    hwrng: via_rng - Fix memory scribbling on some CPUs
    
    It has been reported that on at least one Nano CPU the xstore
    instruction will write as many as 16 bytes of data to the output
    buffer.
    
    This causes memory corruption as we use rng->priv which is only
    4-8 bytes long.
    
    This patch fixes this by using an intermediate buffer on the stack
    with at least 16 bytes and aligned to a 16-byte boundary.
    
    The problem was observed on the following processor:
    
    processor	: 0
    vendor_id	: CentaurHauls
    cpu family	: 6
    model		: 15
    model name	: VIA Nano processor U2250 (1.6GHz Capable)
    stepping	: 3
    cpu MHz		: 1600.000
    cache size	: 1024 KB
    fdiv_bug	: no
    hlt_bug		: no
    f00f_bug	: no
    coma_bug	: no
    fpu		: yes
    fpu_exception	: yes
    cpuid level	: 10
    wp		: yes
    flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat clflush acpi mmx fxsr sse sse2 ss tm syscall nx lm constant_tsc up rep_good pni monitor vmx est tm2 ssse3 cx16 xtpr rng rng_en ace ace_en ace2 phe phe_en lahf_lm
    bogomips	: 3192.08
    clflush size	: 64
    cache_alignment	: 128
    address sizes	: 36 bits physical, 48 bits virtual
    power management:
    
    Tested-by: Mario 'BitKoenig' Holbe <Mario.Holbe@TU-Ilmenau.DE>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

diff --git a/drivers/char/hw_random/via-rng.c b/drivers/char/hw_random/via-rng.c
index 7f86666..d0387a8 100644
--- a/drivers/char/hw_random/via-rng.c
+++ b/drivers/char/hw_random/via-rng.c
@@ -24,6 +24,7 @@
  * warranty of any kind, whether express or implied.
  */
 
+#include <crypto/padlock.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/hw_random.h>
@@ -34,7 +35,6 @@
 #include <asm/i387.h>
 
 
-#define PFX	KBUILD_MODNAME ": "
 
 
 enum {
@@ -89,8 +89,10 @@ static inline u32 xstore(u32 *addr, u32 edx_in)
 
 static int via_rng_data_present(struct hwrng *rng, int wait)
 {
+	char buf[16 + PADLOCK_ALIGNMENT - STACK_ALIGN] __attribute__
+		((aligned(STACK_ALIGN)));
+	u32 *via_rng_datum = (u32 *)PTR_ALIGN(&buf[0], PADLOCK_ALIGNMENT);
 	u32 bytes_out;
-	u32 *via_rng_datum = (u32 *)(&rng->priv);
 	int i;
 
 	/* We choose the recommended 1-byte-per-instruction RNG rate,
@@ -114,6 +116,7 @@ static int via_rng_data_present(struct hwrng *rng, int wait)
 			break;
 		udelay(10);
 	}
+	rng->priv = *via_rng_datum;
 	return bytes_out ? 1 : 0;
 }

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

end of thread, other threads:[~2011-01-07  3:55 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <4D1A8200.4010609@lwfinger.net>
     [not found] ` <20101229195440.GD5838@darkside.kls.lan>
     [not found]   ` <4D1BD2B0.4020101@lwfinger.net>
     [not found]     ` <20101230012003.GA2665@darkside.kls.lan>
     [not found]       ` <4D1BF056.3060909@lwfinger.net>
     [not found]         ` <20101230143406.GA23219@darkside.kls.lan>
     [not found]           ` <4D1CD161.4040107@lwfinger.net>
     [not found]             ` <20101230204522.GC23219@darkside.kls.lan>
     [not found]               ` <4D1D0C61.9050800@lwfinger.net>
2010-12-31  0:37                 ` 2.6.37-rc7: Regression: b43: crashes in hwrng_register() Herbert Xu
2010-12-31  0:46                   ` Larry Finger
2010-12-31  2:25                     ` Mario 'BitKoenig' Holbe
2010-12-31  2:46                       ` Herbert Xu
2010-12-31  8:51                         ` Mario 'BitKoenig' Holbe
2011-01-04  4:33                           ` Herbert Xu
2011-01-04 12:19                             ` Mario 'BitKoenig' Holbe
2011-01-04 12:38                               ` Herbert Xu
2011-01-04 12:57                                 ` Mario 'BitKoenig' Holbe
2011-01-04 22:42                                   ` Herbert Xu
2011-01-04 23:06                                     ` Mario 'BitKoenig' Holbe
2011-01-04 23:26                                       ` Larry Finger
2011-01-04 23:35                                       ` Mario 'BitKoenig' Holbe
2011-01-05  0:30                                       ` Herbert Xu
2011-01-05  1:45                                         ` Mario 'BitKoenig' Holbe
2011-01-05  3:52                                         ` Mario 'BitKoenig' Holbe
2011-01-05  5:47                                           ` Herbert Xu
2011-01-05 13:16                                             ` Mario 'BitKoenig' Holbe
2011-01-06  6:12                                               ` Herbert Xu
     [not found]                                               ` <20110106061241.GA18939@gondor.apana.org.au>
2011-01-06 13:15                                                 ` Mario 'BitKoenig' Holbe
2011-01-06 13:35                                                   ` Herbert Xu
2011-01-06 13:56                                                     ` Larry Finger
2011-01-06 14:42                                                     ` Mario 'BitKoenig' Holbe
2011-01-07  3:49                                                       ` Herbert Xu
2011-01-07  3:54                                                         ` crypto: padlock - Move padlock.h into include/crypto Herbert Xu
2011-01-07  3:55                                                           ` hwrng: via_rng - Fix memory scribbling on some CPUs Herbert Xu
2011-01-05  0:14                                     ` 2.6.37-rc7: Regression: b43: crashes in hwrng_register() Larry Finger
2011-01-05  0:19                                       ` Herbert Xu
2011-01-05  1:38                                         ` Larry Finger

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