2006-05-16 15:24:23

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH] selinux: endian fix

Signed-off-by: Alexey Dobriyan <[email protected]>
---

--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -3231,7 +3231,7 @@ static int selinux_socket_sock_rcv_skb(s
goto out;

/* Handle mapped IPv4 packets arriving via IPv6 sockets */
- if (family == PF_INET6 && skb->protocol == ntohs(ETH_P_IP))
+ if (family == PF_INET6 && skb->protocol == htons(ETH_P_IP))
family = PF_INET;

read_lock_bh(&sk->sk_callback_lock);


2006-05-16 15:54:07

by James Morris

[permalink] [raw]
Subject: Re: [PATCH] selinux: endian fix

On Tue, 16 May 2006, Alexey Dobriyan wrote:

> Signed-off-by: Alexey Dobriyan <[email protected]>

Hmm, I'm certain this was tested (perhaps on a BE machine, though). In any
case skb->protocol should definitely be network byte order.

Acked-by: James Morris <[email protected]>



> --- a/security/selinux/hooks.c
> +++ b/security/selinux/hooks.c
> @@ -3231,7 +3231,7 @@ static int selinux_socket_sock_rcv_skb(s
> goto out;
>
> /* Handle mapped IPv4 packets arriving via IPv6 sockets */
> - if (family == PF_INET6 && skb->protocol == ntohs(ETH_P_IP))
> + if (family == PF_INET6 && skb->protocol == htons(ETH_P_IP))
> family = PF_INET;
>
> read_lock_bh(&sk->sk_callback_lock);
>

--
James Morris
<[email protected]>

2006-05-16 16:24:19

by Andreas Schwab

[permalink] [raw]
Subject: Re: [PATCH] selinux: endian fix

James Morris <[email protected]> writes:

> On Tue, 16 May 2006, Alexey Dobriyan wrote:
>
>> Signed-off-by: Alexey Dobriyan <[email protected]>
>
> Hmm, I'm certain this was tested (perhaps on a BE machine, though).

ntohs and htons are identical operations. Either you swap or you don't,
but there is only one way to swap a short.

Andreas.

--
Andreas Schwab, SuSE Labs, [email protected]
SuSE Linux Products GmbH, Maxfeldstra?e 5, 90409 N?rnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."

2006-05-16 16:30:22

by James Morris

[permalink] [raw]
Subject: Re: [PATCH] selinux: endian fix

On Tue, 16 May 2006, Andreas Schwab wrote:

> ntohs and htons are identical operations. Either you swap or you don't,
> but there is only one way to swap a short.

Indeed.


--
James Morris
<[email protected]>

2006-05-16 16:34:34

by Al Viro

[permalink] [raw]
Subject: Re: [PATCH] selinux: endian fix

On Tue, May 16, 2006 at 06:24:14PM +0200, Andreas Schwab wrote:
> James Morris <[email protected]> writes:
>
> > On Tue, 16 May 2006, Alexey Dobriyan wrote:
> >
> >> Signed-off-by: Alexey Dobriyan <[email protected]>
> >
> > Hmm, I'm certain this was tested (perhaps on a BE machine, though).
>
> ntohs and htons are identical operations. Either you swap or you don't,
> but there is only one way to swap a short.

Indeed, but that kind of crap still deserves a fix - same result, but
use that kind of misuse is begging for bugs later on.

2006-05-16 17:42:22

by Jan Engelhardt

[permalink] [raw]
Subject: Re: [PATCH] selinux: endian fix

>>> Signed-off-by: Alexey Dobriyan <[email protected]>
>>
>> Hmm, I'm certain this was tested (perhaps on a BE machine, though).
>
>ntohs and htons are identical operations. Either you swap or you don't,
>but there is only one way to swap a short.
>
...unless PDPs start to get attractive again. :>


Jan Engelhardt
--

2006-05-16 17:51:16

by Andreas Schwab

[permalink] [raw]
Subject: Re: [PATCH] selinux: endian fix

Jan Engelhardt <[email protected]> writes:

>>>> Signed-off-by: Alexey Dobriyan <[email protected]>
>>>
>>> Hmm, I'm certain this was tested (perhaps on a BE machine, though).
>>
>>ntohs and htons are identical operations. Either you swap or you don't,
>>but there is only one way to swap a short.
>>
> ...unless PDPs start to get attractive again. :>

No. There are only two ways to order two bytes.

Andreas.

--
Andreas Schwab, SuSE Labs, [email protected]
SuSE Linux Products GmbH, Maxfeldstra?e 5, 90409 N?rnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."

2006-05-17 00:55:50

by Peter Chubb

[permalink] [raw]
Subject: Re: [PATCH] selinux: endian fix

>>>>> "James" == James Morris <[email protected]> writes:

James> On Tue, 16 May 2006, Alexey Dobriyan wrote:
>> Signed-off-by: Alexey Dobriyan <[email protected]>

James> Hmm, I'm certain this was tested (perhaps on a BE machine,
James> though). In any case skb->protocol should definitely be network
James> byte order.

On all architectures, ntohs is the same as htons -- either the two
bytes are swapped or they're not.


--
Dr Peter Chubb http://www.gelato.unsw.edu.au peterc AT gelato.unsw.edu.au
http://www.ertos.nicta.com.au ERTOS within National ICT Australia