kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* Dubios pointer casting with put_user()
@ 2020-07-17  0:13 Richard Sailer
  2020-07-17  0:19 ` Richard Sailer
  2020-07-17 22:46 ` Valdis Klētnieks
  0 siblings, 2 replies; 5+ messages in thread
From: Richard Sailer @ 2020-07-17  0:13 UTC (permalink / raw)
  To: kernelnewbies


[-- Attachment #1.1.1: Type: text/plain, Size: 803 bytes --]

Hi,

In the following example from net/dccp/proto.c the pointer given
put_user() is casted to (int __user *) although the value to copy is a
unsigned long. Is this (correctness and security wise) sane? Because as
I understand it put_user() determines the amount it copies from the
pointer type.

```
		unsigned long amount = 0;

		skb = skb_peek(&sk->sk_receive_queue);
		if (skb != NULL) {
			amount = skb->len;
		}
		rc = put_user(amount, (int __user *)arg);
```

Also skb->len is an unsigned int realisticly in most cases < 9000 (and
in all cases I can imagine < int_max (with 16 bit)).

I would like to declare amount as int outside of the switch case
statement (because I  need it in another case statement as signed int)
would it be safe to do so?

Thanks,
-- Richard


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

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

end of thread, other threads:[~2020-07-19 22:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-17  0:13 Dubios pointer casting with put_user() Richard Sailer
2020-07-17  0:19 ` Richard Sailer
2020-07-17 22:46 ` Valdis Klētnieks
2020-07-19 12:15   ` Richard Sailer
2020-07-19 22:50     ` Valdis Klētnieks

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