All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi scsi_transport_iscsi.c: fix misuse of %llu in scsi_transport_iscsi.c
@ 2021-10-09  3:02 Guo Zhi
  2021-10-09  3:14 ` Joe Perches
  0 siblings, 1 reply; 7+ messages in thread
From: Guo Zhi @ 2021-10-09  3:02 UTC (permalink / raw)
  To: Lee Duncan, Chris Leech, James E.J. Bottomley, Martin K. Petersen
  Cc: Guo Zhi, open-iscsi, linux-scsi, linux-kernel

Pointers should be printed with %p or %px rather than
cast to (unsigned long long) and printed with %llu.
Change %llu to %p to print the pointer into sysfs.

Signed-off-by: Guo Zhi <qtxuning1999@sjtu.edu.cn>
---
 drivers/scsi/scsi_transport_iscsi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
index 922e4c7bd88e..7d6a570ebf48 100644
--- a/drivers/scsi/scsi_transport_iscsi.c
+++ b/drivers/scsi/scsi_transport_iscsi.c
@@ -129,8 +129,8 @@ show_transport_handle(struct device *dev, struct device_attribute *attr,
 
 	if (!capable(CAP_SYS_ADMIN))
 		return -EACCES;
-	return sysfs_emit(buf, "%llu\n",
-		  (unsigned long long)iscsi_handle(priv->iscsi_transport));
+	return sysfs_emit(buf, "%p\n",
+		iscsi_ptr(priv->iscsi_transport));
 }
 static DEVICE_ATTR(handle, S_IRUGO, show_transport_handle, NULL);
 
-- 
2.33.0


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

* Re: [PATCH] scsi scsi_transport_iscsi.c: fix misuse of %llu in scsi_transport_iscsi.c
  2021-10-09  3:02 [PATCH] scsi scsi_transport_iscsi.c: fix misuse of %llu in scsi_transport_iscsi.c Guo Zhi
@ 2021-10-09  3:14 ` Joe Perches
  2021-10-09  4:35   ` Guo Zhi
  2021-10-11  6:35   ` Antw: [EXT] " Ulrich Windl
  0 siblings, 2 replies; 7+ messages in thread
From: Joe Perches @ 2021-10-09  3:14 UTC (permalink / raw)
  To: Guo Zhi, Lee Duncan, Chris Leech, James E.J. Bottomley,
	Martin K. Petersen
  Cc: open-iscsi, linux-scsi, linux-kernel

On Sat, 2021-10-09 at 11:02 +0800, Guo Zhi wrote:
> Pointers should be printed with %p or %px rather than
> cast to (unsigned long long) and printed with %llu.
> Change %llu to %p to print the pointer into sysfs.
][]
> diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
[]
> @@ -129,8 +129,8 @@ show_transport_handle(struct device *dev, struct device_attribute *attr,
>  
> 
>  	if (!capable(CAP_SYS_ADMIN))
>  		return -EACCES;
> -	return sysfs_emit(buf, "%llu\n",
> -		  (unsigned long long)iscsi_handle(priv->iscsi_transport));
> +	return sysfs_emit(buf, "%p\n",
> +		iscsi_ptr(priv->iscsi_transport));

iscsi_transport is a pointer isn't it?

so why not just

	return sysfs_emit(buf, "%p\n", priv->iscsi_transport);

?


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

* Re: [PATCH] scsi scsi_transport_iscsi.c: fix misuse of %llu in scsi_transport_iscsi.c
  2021-10-09  3:14 ` Joe Perches
@ 2021-10-09  4:35   ` Guo Zhi
  2021-10-11  6:35   ` Antw: [EXT] " Ulrich Windl
  1 sibling, 0 replies; 7+ messages in thread
From: Guo Zhi @ 2021-10-09  4:35 UTC (permalink / raw)
  To: Joe Perches
  Cc: Lee Duncan, Chris Leech, James E.J. Bottomley,
	Martin K. Petersen, open-iscsi, linux-scsi, linux-kernel

I will send a V2 patch.

----- 原始邮件 -----
发件人: "Joe Perches" <joe@perches.com>
收件人: "Guo Zhi" <qtxuning1999@sjtu.edu.cn>, "Lee Duncan" <lduncan@suse.com>, "Chris Leech" <cleech@redhat.com>, "James E.J. Bottomley" <jejb@linux.ibm.com>, "Martin K. Petersen" <martin.petersen@oracle.com>
抄送: open-iscsi@googlegroups.com, linux-scsi@vger.kernel.org, "linux-kernel" <linux-kernel@vger.kernel.org>
发送时间: 星期六, 2021年 10 月 09日 上午 11:14:36
主题: Re: [PATCH] scsi scsi_transport_iscsi.c: fix misuse of %llu in scsi_transport_iscsi.c

On Sat, 2021-10-09 at 11:02 +0800, Guo Zhi wrote:
> Pointers should be printed with %p or %px rather than
> cast to (unsigned long long) and printed with %llu.
> Change %llu to %p to print the pointer into sysfs.
][]
> diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
[]
> @@ -129,8 +129,8 @@ show_transport_handle(struct device *dev, struct device_attribute *attr,
>  
> 
>  	if (!capable(CAP_SYS_ADMIN))
>  		return -EACCES;
> -	return sysfs_emit(buf, "%llu\n",
> -		  (unsigned long long)iscsi_handle(priv->iscsi_transport));
> +	return sysfs_emit(buf, "%p\n",
> +		iscsi_ptr(priv->iscsi_transport));

iscsi_transport is a pointer isn't it?

so why not just

	return sysfs_emit(buf, "%p\n", priv->iscsi_transport);

?

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

* Antw: [EXT] Re: [PATCH] scsi scsi_transport_iscsi.c: fix misuse of %llu in scsi_transport_iscsi.c
  2021-10-09  3:14 ` Joe Perches
  2021-10-09  4:35   ` Guo Zhi
@ 2021-10-11  6:35   ` Ulrich Windl
  2021-10-11 15:29     ` Mike Christie
  1 sibling, 1 reply; 7+ messages in thread
From: Ulrich Windl @ 2021-10-11  6:35 UTC (permalink / raw)
  To: jejb, martin.petersen, Chris Leech, qtxuning1999, Lee Duncan
  Cc: open-iscsi, linux-kernel, linux-scsi

>>> Joe Perches <joe@perches.com> schrieb am 09.10.2021 um 05:14 in Nachricht
<5daf69b365e23ceecee911c4d0f2f66a0b9ec95c.camel@perches.com>:
> On Sat, 2021-10-09 at 11:02 +0800, Guo Zhi wrote:
>> Pointers should be printed with %p or %px rather than
>> cast to (unsigned long long) and printed with %llu.
>> Change %llu to %p to print the pointer into sysfs.
> ][]
>> diff --git a/drivers/scsi/scsi_transport_iscsi.c 
> b/drivers/scsi/scsi_transport_iscsi.c
> []
>> @@ -129,8 +129,8 @@ show_transport_handle(struct device *dev, struct 
> device_attribute *attr,
>>  
>> 
>>  	if (!capable(CAP_SYS_ADMIN))
>>  		return -EACCES;
>> -	return sysfs_emit(buf, "%llu\n",
>> -		  (unsigned long long)iscsi_handle(priv->iscsi_transport));
>> +	return sysfs_emit(buf, "%p\n",
>> +		iscsi_ptr(priv->iscsi_transport));
> 
> iscsi_transport is a pointer isn't it?
> 
> so why not just
> 
> 	return sysfs_emit(buf, "%p\n", priv->iscsi_transport);

Isn't the difference that %p outputs hex, while %u outputs decimal?

> 
> ?
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "open-iscsi" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to open-iscsi+unsubscribe@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/open-iscsi/5daf69b365e23ceecee911c4d0f2f66a 
> 0b9ec95c.camel%40perches.com.





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

* Re: Antw: [EXT] Re: [PATCH] scsi scsi_transport_iscsi.c: fix misuse of %llu in scsi_transport_iscsi.c
  2021-10-11  6:35   ` Antw: [EXT] " Ulrich Windl
@ 2021-10-11 15:29     ` Mike Christie
  2021-10-12  7:04       ` Ulrich Windl
  2021-10-15  7:36       ` Guo Zhi
  0 siblings, 2 replies; 7+ messages in thread
From: Mike Christie @ 2021-10-11 15:29 UTC (permalink / raw)
  To: Ulrich Windl, jejb, martin.petersen, Chris Leech, qtxuning1999,
	Lee Duncan
  Cc: open-iscsi, linux-kernel, linux-scsi

On 10/11/21 1:35 AM, Ulrich Windl wrote:
>>>> Joe Perches <joe@perches.com> schrieb am 09.10.2021 um 05:14 in Nachricht
> <5daf69b365e23ceecee911c4d0f2f66a0b9ec95c.camel@perches.com>:
>> On Sat, 2021-10-09 at 11:02 +0800, Guo Zhi wrote:
>>> Pointers should be printed with %p or %px rather than
>>> cast to (unsigned long long) and printed with %llu.
>>> Change %llu to %p to print the pointer into sysfs.
>> ][]
>>> diff --git a/drivers/scsi/scsi_transport_iscsi.c 
>> b/drivers/scsi/scsi_transport_iscsi.c
>> []
>>> @@ -129,8 +129,8 @@ show_transport_handle(struct device *dev, struct 
>> device_attribute *attr,
>>>  
>>>
>>>  	if (!capable(CAP_SYS_ADMIN))
>>>  		return -EACCES;
>>> -	return sysfs_emit(buf, "%llu\n",
>>> -		  (unsigned long long)iscsi_handle(priv->iscsi_transport));
>>> +	return sysfs_emit(buf, "%p\n",
>>> +		iscsi_ptr(priv->iscsi_transport));
>>
>> iscsi_transport is a pointer isn't it?
>>
>> so why not just
>>
>> 	return sysfs_emit(buf, "%p\n", priv->iscsi_transport);
> 
> Isn't the difference that %p outputs hex, while %u outputs decimal?
> 

Yeah, I think this patch will break userspace, because it doesn't know it's
a pointer. It could be doing:

sscanf(str, "%llu", &val);

The value is just later passed back to the kernel to look up a driver in
iscsi_if_transport_lookup:

        list_for_each_entry(priv, &iscsi_transports, list) {
                if (tt == priv->iscsi_transport) {

so we could just replace priv->transport with an int and use an ida to assign
the value.

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

* Re: Antw: [EXT] Re: [PATCH] scsi scsi_transport_iscsi.c: fix misuse of %llu in scsi_transport_iscsi.c
  2021-10-11 15:29     ` Mike Christie
@ 2021-10-12  7:04       ` Ulrich Windl
  2021-10-15  7:36       ` Guo Zhi
  1 sibling, 0 replies; 7+ messages in thread
From: Ulrich Windl @ 2021-10-12  7:04 UTC (permalink / raw)
  To: jejb, martin.petersen, Chris Leech, qtxuning1999, Lee Duncan
  Cc: open-iscsi, linux-kernel, linux-scsi

>>> Mike Christie <michael.christie@oracle.com> schrieb am 11.10.2021 um 17:29 in
Nachricht <ae7a82c2-5b19-493a-8d61-cdccb00cf46c@oracle.com>:
> On 10/11/21 1:35 AM, Ulrich Windl wrote:
>>>>> Joe Perches <joe@perches.com> schrieb am 09.10.2021 um 05:14 in Nachricht
>> <5daf69b365e23ceecee911c4d0f2f66a0b9ec95c.camel@perches.com>:
>>> On Sat, 2021-10-09 at 11:02 +0800, Guo Zhi wrote:
>>>> Pointers should be printed with %p or %px rather than
>>>> cast to (unsigned long long) and printed with %llu.
>>>> Change %llu to %p to print the pointer into sysfs.
>>> ][]
>>>> diff --git a/drivers/scsi/scsi_transport_iscsi.c 
>>> b/drivers/scsi/scsi_transport_iscsi.c
>>> []
>>>> @@ -129,8 +129,8 @@ show_transport_handle(struct device *dev, struct 
>>> device_attribute *attr,
>>>>  
>>>>
>>>>  	if (!capable(CAP_SYS_ADMIN))
>>>>  		return -EACCES;
>>>> -	return sysfs_emit(buf, "%llu\n",
>>>> -		  (unsigned long long)iscsi_handle(priv->iscsi_transport));
>>>> +	return sysfs_emit(buf, "%p\n",
>>>> +		iscsi_ptr(priv->iscsi_transport));
>>>
>>> iscsi_transport is a pointer isn't it?
>>>
>>> so why not just
>>>
>>> 	return sysfs_emit(buf, "%p\n", priv->iscsi_transport);
>> 
>> Isn't the difference that %p outputs hex, while %u outputs decimal?
>> 
> 
> Yeah, I think this patch will break userspace, because it doesn't know it's
> a pointer. It could be doing:
> 
> sscanf(str, "%llu", &val);
> 
> The value is just later passed back to the kernel to look up a driver in
> iscsi_if_transport_lookup:
> 
>         list_for_each_entry(priv, &iscsi_transports, list) {
>                 if (tt == priv->iscsi_transport) {
> 
> so we could just replace priv->transport with an int and use an ida to assign
> the value.

I'm not in the details, but if that value is used as an ID, shouldn't it have been something like "ID%llu" right from the start?
If so it would be rather easy to use "ID%p" instead (if the syntax of the ID is left unspecified). At least nobody would treat it as a number.

Regards,
Ulrich


> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "open-iscsi" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to open-iscsi+unsubscribe@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/open-iscsi/ae7a82c2-5b19-493a-8d61-cdccb00c 
> f46c%40oracle.com.





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

* Re: Antw: [EXT] Re: [PATCH] scsi scsi_transport_iscsi.c: fix misuse of %llu in scsi_transport_iscsi.c
  2021-10-11 15:29     ` Mike Christie
  2021-10-12  7:04       ` Ulrich Windl
@ 2021-10-15  7:36       ` Guo Zhi
  1 sibling, 0 replies; 7+ messages in thread
From: Guo Zhi @ 2021-10-15  7:36 UTC (permalink / raw)
  To: Mike Christie, Ulrich Windl, jejb, martin.petersen, Chris Leech,
	Lee Duncan
  Cc: open-iscsi, linux-kernel, linux-scsi

On 2021/10/11 23:29, Mike Christie wrote:
> On 10/11/21 1:35 AM, Ulrich Windl wrote:
>>>>> Joe Perches <joe@perches.com> schrieb am 09.10.2021 um 05:14 in Nachricht
>> <5daf69b365e23ceecee911c4d0f2f66a0b9ec95c.camel@perches.com>:
>>> On Sat, 2021-10-09 at 11:02 +0800, Guo Zhi wrote:
>>>> Pointers should be printed with %p or %px rather than
>>>> cast to (unsigned long long) and printed with %llu.
>>>> Change %llu to %p to print the pointer into sysfs.
>>> ][]
>>>> diff --git a/drivers/scsi/scsi_transport_iscsi.c
>>> b/drivers/scsi/scsi_transport_iscsi.c
>>> []
>>>> @@ -129,8 +129,8 @@ show_transport_handle(struct device *dev, struct
>>> device_attribute *attr,
>>>>   
>>>>
>>>>   	if (!capable(CAP_SYS_ADMIN))
>>>>   		return -EACCES;
>>>> -	return sysfs_emit(buf, "%llu\n",
>>>> -		  (unsigned long long)iscsi_handle(priv->iscsi_transport));
>>>> +	return sysfs_emit(buf, "%p\n",
>>>> +		iscsi_ptr(priv->iscsi_transport));
>>> iscsi_transport is a pointer isn't it?
>>>
>>> so why not just
>>>
>>> 	return sysfs_emit(buf, "%p\n", priv->iscsi_transport);
>> Isn't the difference that %p outputs hex, while %u outputs decimal?
>>
> Yeah, I think this patch will break userspace, because it doesn't know it's
> a pointer. It could be doing:
>
> sscanf(str, "%llu", &val);
>
> The value is just later passed back to the kernel to look up a driver in
> iscsi_if_transport_lookup:
>
>          list_for_each_entry(priv, &iscsi_transports, list) {
>                  if (tt == priv->iscsi_transport) {
>
> so we could just replace priv->transport with an int and use an ida to assign
> the value.

Taking security into consideration, We should not print kernel pointer 
into sysfs.

However if this is a special pointer to lookup a driver,  It's really 
tricky for me to fix it,

as I don't have a scsi device to test my code.


Guo



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

end of thread, other threads:[~2021-10-15  7:37 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-09  3:02 [PATCH] scsi scsi_transport_iscsi.c: fix misuse of %llu in scsi_transport_iscsi.c Guo Zhi
2021-10-09  3:14 ` Joe Perches
2021-10-09  4:35   ` Guo Zhi
2021-10-11  6:35   ` Antw: [EXT] " Ulrich Windl
2021-10-11 15:29     ` Mike Christie
2021-10-12  7:04       ` Ulrich Windl
2021-10-15  7:36       ` Guo Zhi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.