* [PATCH] drivers/net/slip: prevent data alignment fault
@ 2023-10-02 2:45 William Tambe
2023-10-02 6:31 ` Paul Mackerras
0 siblings, 1 reply; 6+ messages in thread
From: William Tambe @ 2023-10-02 2:45 UTC (permalink / raw)
To: linux-ppp
From 594e53fa4913b1cb6232dbcc73d905a94c0cae73 Mon Sep 17 00:00:00 2001
From: William Tambe <tambewilliam@gmail.com>
Date: Sun, 1 Oct 2023 21:38:15 -0500
Subject: [PATCH] drivers/net/slip: prevent data alignment fault
Prevent data alignment fault on architectures which cannot
do unaligned memory access.
---
drivers/net/slip/slhc.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
index ba93bab948e0..08fd570a6d40 100644
--- a/drivers/net/slip/slhc.c
+++ b/drivers/net/slip/slhc.c
@@ -459,8 +459,8 @@ slhc_compress(struct slcompress *comp, unsigned
char *icp, int isize,
*cpp = ocp;
*cp++ = changes;
}
- *(__sum16 *)cp = csum;
- cp += 2;
+ *cp++ = (char)(csum&0xff);
+ *cp++ = (char)((csum>>8)&0xff);
/* deltaS is now the size of the change section of the compressed header */
memcpy(cp,new_seq,deltaS); /* Write list of deltas */
memcpy(cp+deltaS,icp+hlen,isize-hlen);
@@ -534,7 +534,7 @@ slhc_uncompress(struct slcompress *comp, unsigned
char *icp, int isize)
thp = &cs->cs_tcp;
ip = &cs->cs_ip;
- thp->check = *(__sum16 *)cp;
+ thp->check = (((__sum16)*cp)|(((__sum16)*(cp+1))<<8));
cp += 2;
thp->psh = (changes & TCP_PUSH_BIT) ? 1 : 0;
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] drivers/net/slip: prevent data alignment fault
2023-10-02 2:45 [PATCH] drivers/net/slip: prevent data alignment fault William Tambe
@ 2023-10-02 6:31 ` Paul Mackerras
2023-10-02 15:24 ` William Tambe
0 siblings, 1 reply; 6+ messages in thread
From: Paul Mackerras @ 2023-10-02 6:31 UTC (permalink / raw)
To: William Tambe; +Cc: linux-ppp
On Sun, Oct 01, 2023 at 09:45:57PM -0500, William Tambe wrote:
> >From 594e53fa4913b1cb6232dbcc73d905a94c0cae73 Mon Sep 17 00:00:00 2001
> From: William Tambe <tambewilliam@gmail.com>
> Date: Sun, 1 Oct 2023 21:38:15 -0500
> Subject: [PATCH] drivers/net/slip: prevent data alignment fault
>
> Prevent data alignment fault on architectures which cannot
> do unaligned memory access.
> ---
> drivers/net/slip/slhc.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
> index ba93bab948e0..08fd570a6d40 100644
> --- a/drivers/net/slip/slhc.c
> +++ b/drivers/net/slip/slhc.c
> @@ -459,8 +459,8 @@ slhc_compress(struct slcompress *comp, unsigned
> char *icp, int isize,
> *cpp = ocp;
> *cp++ = changes;
> }
> - *(__sum16 *)cp = csum;
> - cp += 2;
> + *cp++ = (char)(csum&0xff);
> + *cp++ = (char)((csum>>8)&0xff);
You just changed the meaning of the code on big-endian machines.
I think it would be better to use put_unaligned() here, and
get_unaligned() below.
> /* deltaS is now the size of the change section of the compressed header */
> memcpy(cp,new_seq,deltaS); /* Write list of deltas */
> memcpy(cp+deltaS,icp+hlen,isize-hlen);
> @@ -534,7 +534,7 @@ slhc_uncompress(struct slcompress *comp, unsigned
> char *icp, int isize)
> thp = &cs->cs_tcp;
> ip = &cs->cs_ip;
>
> - thp->check = *(__sum16 *)cp;
> + thp->check = (((__sum16)*cp)|(((__sum16)*(cp+1))<<8));
> cp += 2;
>
> thp->psh = (changes & TCP_PUSH_BIT) ? 1 : 0;
> --
> 2.34.1
Paul.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] drivers/net/slip: prevent data alignment fault
2023-10-02 6:31 ` Paul Mackerras
@ 2023-10-02 15:24 ` William Tambe
2023-11-13 1:21 ` Willem de Bruijn
0 siblings, 1 reply; 6+ messages in thread
From: William Tambe @ 2023-10-02 15:24 UTC (permalink / raw)
To: Paul Mackerras; +Cc: linux-ppp
Thanks, sending v2 of the patch that uses put_unaligned() here, and
get_unaligned().
William
On Mon, Oct 2, 2023 at 1:31 AM Paul Mackerras <paulus@ozlabs.org> wrote:
>
> On Sun, Oct 01, 2023 at 09:45:57PM -0500, William Tambe wrote:
> > >From 594e53fa4913b1cb6232dbcc73d905a94c0cae73 Mon Sep 17 00:00:00 2001
> > From: William Tambe <tambewilliam@gmail.com>
> > Date: Sun, 1 Oct 2023 21:38:15 -0500
> > Subject: [PATCH] drivers/net/slip: prevent data alignment fault
> >
> > Prevent data alignment fault on architectures which cannot
> > do unaligned memory access.
> > ---
> > drivers/net/slip/slhc.c | 6 +++---
> > 1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
> > index ba93bab948e0..08fd570a6d40 100644
> > --- a/drivers/net/slip/slhc.c
> > +++ b/drivers/net/slip/slhc.c
> > @@ -459,8 +459,8 @@ slhc_compress(struct slcompress *comp, unsigned
> > char *icp, int isize,
> > *cpp = ocp;
> > *cp++ = changes;
> > }
> > - *(__sum16 *)cp = csum;
> > - cp += 2;
> > + *cp++ = (char)(csum&0xff);
> > + *cp++ = (char)((csum>>8)&0xff);
>
> You just changed the meaning of the code on big-endian machines.
>
> I think it would be better to use put_unaligned() here, and
> get_unaligned() below.
>
> > /* deltaS is now the size of the change section of the compressed header */
> > memcpy(cp,new_seq,deltaS); /* Write list of deltas */
> > memcpy(cp+deltaS,icp+hlen,isize-hlen);
> > @@ -534,7 +534,7 @@ slhc_uncompress(struct slcompress *comp, unsigned
> > char *icp, int isize)
> > thp = &cs->cs_tcp;
> > ip = &cs->cs_ip;
> >
> > - thp->check = *(__sum16 *)cp;
> > + thp->check = (((__sum16)*cp)|(((__sum16)*(cp+1))<<8));
> > cp += 2;
> >
> > thp->psh = (changes & TCP_PUSH_BIT) ? 1 : 0;
> > --
> > 2.34.1
>
> Paul.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] drivers/net/slip: prevent data alignment fault
2023-10-02 15:24 ` William Tambe
@ 2023-11-13 1:21 ` Willem de Bruijn
0 siblings, 0 replies; 6+ messages in thread
From: Willem de Bruijn @ 2023-11-13 1:21 UTC (permalink / raw)
To: William Tambe, Paul Mackerras; +Cc: linux-ppp
William Tambe wrote:
> Thanks, sending v2 of the patch that uses put_unaligned() here, and
> get_unaligned().
I can't find your v2 archived in lore, so responding to this thread.
If you want a patch merged to networking, you'll have to cc
netdev@vger.kernel.org and the networking maintainers.
Consider running scripts/get_maintainer.pl and also see
https://www.kernel.org/doc/Documentation/process/maintainer-netdev.rst
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] drivers/net/slip: prevent data alignment fault
2023-10-01 22:19 William Tambe
@ 2023-10-02 1:10 ` William Tambe
0 siblings, 0 replies; 6+ messages in thread
From: William Tambe @ 2023-10-02 1:10 UTC (permalink / raw)
To: linux-ppp
Please, disregard patch, as it is incorrect; resending correct patch
shortly with better explanation of the fix.
On Sun, Oct 1, 2023 at 5:19 PM William Tambe <tambewilliam@gmail.com> wrote:
>
> From c630b0aea59c1dced626c9da95fd71033763d606 Mon Sep 17 00:00:00 2001
> From: William Tambe <tambewilliam@gmail.com>
> Date: Sun, 1 Oct 2023 17:17:03 -0500
> Subject: [PATCH] drivers/net/slip: prevent data alignment fault
>
> ---
> drivers/net/slip/slhc.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
> index ba93bab948e0..78b07c46fe08 100644
> --- a/drivers/net/slip/slhc.c
> +++ b/drivers/net/slip/slhc.c
> @@ -459,7 +459,8 @@ slhc_compress(struct slcompress *comp, unsigned
> char *icp, int isize,
> *cpp = ocp;
> *cp++ = changes;
> }
> - *(__sum16 *)cp = csum;
> + *cp++ = (char)(csum&0xff);
> + *cp++ = (char)((csum>>8)&0xff);
> cp += 2;
> /* deltaS is now the size of the change section of the compressed header */
> memcpy(cp,new_seq,deltaS); /* Write list of deltas */
> @@ -534,7 +535,7 @@ slhc_uncompress(struct slcompress *comp, unsigned
> char *icp, int isize)
> thp = &cs->cs_tcp;
> ip = &cs->cs_ip;
>
> - thp->check = *(__sum16 *)cp;
> + thp->check = (((__sum16)*cp)|(((__sum16)*(cp+1))<<8));
> cp += 2;
>
> thp->psh = (changes & TCP_PUSH_BIT) ? 1 : 0;
> --
> 2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] drivers/net/slip: prevent data alignment fault
@ 2023-10-01 22:19 William Tambe
2023-10-02 1:10 ` William Tambe
0 siblings, 1 reply; 6+ messages in thread
From: William Tambe @ 2023-10-01 22:19 UTC (permalink / raw)
To: linux-ppp
From c630b0aea59c1dced626c9da95fd71033763d606 Mon Sep 17 00:00:00 2001
From: William Tambe <tambewilliam@gmail.com>
Date: Sun, 1 Oct 2023 17:17:03 -0500
Subject: [PATCH] drivers/net/slip: prevent data alignment fault
---
drivers/net/slip/slhc.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
index ba93bab948e0..78b07c46fe08 100644
--- a/drivers/net/slip/slhc.c
+++ b/drivers/net/slip/slhc.c
@@ -459,7 +459,8 @@ slhc_compress(struct slcompress *comp, unsigned
char *icp, int isize,
*cpp = ocp;
*cp++ = changes;
}
- *(__sum16 *)cp = csum;
+ *cp++ = (char)(csum&0xff);
+ *cp++ = (char)((csum>>8)&0xff);
cp += 2;
/* deltaS is now the size of the change section of the compressed header */
memcpy(cp,new_seq,deltaS); /* Write list of deltas */
@@ -534,7 +535,7 @@ slhc_uncompress(struct slcompress *comp, unsigned
char *icp, int isize)
thp = &cs->cs_tcp;
ip = &cs->cs_ip;
- thp->check = *(__sum16 *)cp;
+ thp->check = (((__sum16)*cp)|(((__sum16)*(cp+1))<<8));
cp += 2;
thp->psh = (changes & TCP_PUSH_BIT) ? 1 : 0;
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-11-13 1:22 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-02 2:45 [PATCH] drivers/net/slip: prevent data alignment fault William Tambe
2023-10-02 6:31 ` Paul Mackerras
2023-10-02 15:24 ` William Tambe
2023-11-13 1:21 ` Willem de Bruijn
-- strict thread matches above, loose matches on Subject: below --
2023-10-01 22:19 William Tambe
2023-10-02 1:10 ` William Tambe
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).