mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] char/moxa.c: fix endianess and multiple-card issues
@ 2006-08-18 11:39 Dirk Eibach
  2006-08-18 13:35 ` Alexey Dobriyan
  2006-08-20 18:28 ` Alan Cox
  0 siblings, 2 replies; 3+ messages in thread
From: Dirk Eibach @ 2006-08-18 11:39 UTC (permalink / raw)
  To: linux-kernel

From: Dirk Eibach <eibach@gdsys.de>

While testing Moxa C218T/PCI on PowerPC 405EP I found that loading 
firmware using the linux kernel driver fails because calculation of the 
checksum is not endianess independent in the original code.

After I fixed this I found that uploading firmware in a system with 
multiple cards causes a kernel oops. I had a look in the recent moxa 
sources and found that they do some kind of locking there. Applying this 
lock fixed the problem.

This patch applies to kernel 2.6.16.

Signed-off-by: Dirk Eibach <eibach@gdsys.de>
---
--- linux-2.6.16/drivers/char/moxa.c	2006-03-20 06:53:29.000000000 +0100
+++ linux-2.6.16-chameleon/drivers/char/moxa.c	2006-08-18 
13:21:59.000000000 +0200
@@ -143,6 +143,7 @@ typedef struct _moxa_board_conf {

  static moxa_board_conf moxa_boards[MAX_BOARDS];
  static void __iomem *moxaBaseAddr[MAX_BOARDS];
+static int loadstat[MAX_BOARDS]={0,0,0,0};

  struct moxa_str {
  	int type;
@@ -1690,6 +1691,8 @@ int MoxaDriverPoll(void)
  	if (moxaCard == 0)
  		return (-1);
  	for (card = 0; card < MAX_BOARDS; card++) {
+	        if(loadstat[card]==0)
+			continue;
  		if ((ports = moxa_boards[card].numPorts) == 0)
  			continue;
  		if (readb(moxaIntPend[card]) == 0xff) {
@@ -2905,6 +2908,7 @@ static int moxaloadcode(int cardno, unsi
  		}
  		break;
  	}
+	loadstat[cardno] = 1;
  	return (0);
  }

@@ -2922,7 +2926,7 @@ static int moxaloadc218(int cardno, void
  	len1 = len >> 1;
  	ptr = (ushort *) moxaBuff;
  	for (i = 0; i < len1; i++)
-		usum += *(ptr + i);
+		usum += le16_to_cpu(*(ptr + i));
  	retry = 0;
  	do {
  		len1 = len >> 1;
@@ -2994,7 +2998,7 @@ static int moxaloadc320(int cardno, void
  	wlen = len >> 1;
  	uptr = (ushort *) moxaBuff;
  	for (i = 0; i < wlen; i++)
-		usum += uptr[i];
+		usum += le16_to_cpu(uptr[i]);
  	retry = 0;
  	j = 0;
  	do {




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

* Re: [PATCH] char/moxa.c: fix endianess and multiple-card issues
  2006-08-18 11:39 [PATCH] char/moxa.c: fix endianess and multiple-card issues Dirk Eibach
@ 2006-08-18 13:35 ` Alexey Dobriyan
  2006-08-20 18:28 ` Alan Cox
  1 sibling, 0 replies; 3+ messages in thread
From: Alexey Dobriyan @ 2006-08-18 13:35 UTC (permalink / raw)
  To: Dirk Eibach; +Cc: linux-kernel

On Fri, Aug 18, 2006 at 01:39:10PM +0200, Dirk Eibach wrote:
> From: Dirk Eibach <eibach@gdsys.de>
> 
> While testing Moxa C218T/PCI on PowerPC 405EP I found that loading 
> firmware using the linux kernel driver fails because calculation of the 
> checksum is not endianess independent in the original code.
> 
> After I fixed this I found that uploading firmware in a system with 
> multiple cards causes a kernel oops. I had a look in the recent moxa 
> sources and found that they do some kind of locking there. Applying this 
> lock fixed the problem.

Patch for endian bug needs sparse endian annotations as well.
--------------------------------------
[PATCH] moxa: fix checksum endianness

From: Dirk Eibach <eibach@gdsys.de>

While testing Moxa C218T/PCI on PowerPC 405EP I found that loading
firmware using the linux kernel driver fails because calculation of the
checksum is not endianess independent in the original code.

Signed-off-by: Dirk Eibach <eibach@gdsys.de>
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

 drivers/char/moxa.c |   13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

--- a/drivers/char/moxa.c
+++ b/drivers/char/moxa.c
@@ -2910,7 +2910,8 @@ static int moxaloadc218(int cardno, void
 {
 	char retry;
 	int i, j, len1, len2;
-	ushort usum, *ptr, keycode;
+	ushort usum, keycode;
+	__le16 *ptr;
 
 	if (moxa_boards[cardno].boardType == MOXA_BOARD_CP204J)
 		keycode = CP204J_KeyCode;
@@ -2918,9 +2919,9 @@ static int moxaloadc218(int cardno, void
 		keycode = C218_KeyCode;
 	usum = 0;
 	len1 = len >> 1;
-	ptr = (ushort *) moxaBuff;
+	ptr = (__le16 *) moxaBuff;
 	for (i = 0; i < len1; i++)
-		usum += *(ptr + i);
+		usum += le16_to_cpu(*(ptr + i));
 	retry = 0;
 	do {
 		len1 = len >> 1;
@@ -2986,13 +2987,13 @@ static int moxaloadc320(int cardno, void
 {
 	ushort usum;
 	int i, j, wlen, len2, retry;
-	ushort *uptr;
+	__le16 *uptr;
 
 	usum = 0;
 	wlen = len >> 1;
-	uptr = (ushort *) moxaBuff;
+	uptr = (__le16 *) moxaBuff;
 	for (i = 0; i < wlen; i++)
-		usum += uptr[i];
+		usum += le16_to_cpu(uptr[i]);
 	retry = 0;
 	j = 0;
 	do {


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

* Re: [PATCH] char/moxa.c: fix endianess and multiple-card issues
  2006-08-18 11:39 [PATCH] char/moxa.c: fix endianess and multiple-card issues Dirk Eibach
  2006-08-18 13:35 ` Alexey Dobriyan
@ 2006-08-20 18:28 ` Alan Cox
  1 sibling, 0 replies; 3+ messages in thread
From: Alan Cox @ 2006-08-20 18:28 UTC (permalink / raw)
  To: Dirk Eibach; +Cc: linux-kernel, akpm

Ar Gwe, 2006-08-18 am 13:39 +0200, ysgrifennodd Dirk Eibach:
> From: Dirk Eibach <eibach@gdsys.de>
> 
> While testing Moxa C218T/PCI on PowerPC 405EP I found that loading 
> firmware using the linux kernel driver fails because calculation of the 
> checksum is not endianess independent in the original code.

> Signed-off-by: Dirk Eibach <eibach@gdsys.de>

Acked-by: Alan Cox <alan@redhat.com>

Checksum changes are clearly correct. Other changes is an improvement
but not I think enough to handle malicious firmware attacks. That said
such an attacker has CAP_SYS_RAWIO anyway so that part is irrelevant
except for neatness


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

end of thread, other threads:[~2006-08-20 18:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-18 11:39 [PATCH] char/moxa.c: fix endianess and multiple-card issues Dirk Eibach
2006-08-18 13:35 ` Alexey Dobriyan
2006-08-20 18:28 ` Alan Cox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®