linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] SMB2: Fix share type handling
@ 2016-11-21 21:53 Christophe JAILLET
  2016-11-22  8:19 ` walter harms
  2016-11-22 12:18 ` Aurélien Aptel
  0 siblings, 2 replies; 3+ messages in thread
From: Christophe JAILLET @ 2016-11-21 21:53 UTC (permalink / raw)
  To: sfrench
  Cc: linux-cifs, samba-technical, linux-kernel, kernel-janitors,
	Christophe JAILLET

In fs/cifs/smb2pdu.h, we have:
#define SMB2_SHARE_TYPE_DISK    0x01
#define SMB2_SHARE_TYPE_PIPE    0x02
#define SMB2_SHARE_TYPE_PRINT   0x03

Knowing that, with the current code, the SMB2_SHARE_TYPE_PRINT case can
never trigger and printer share would be interpreted as disk share.

So, test the ShareType value for equality instead.

While at it, add some { } to fix a small style issue.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Compile-tested only.

The proposed patch changes a bit the semantic as no masking is performed
anymore. If some upper bits in 'ShareType' are set, it would now be rejected
instead of silently accepted.
---
 fs/cifs/smb2pdu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index 5ca5ea4668a1..600f52994fd9 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -1143,12 +1143,12 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree,
 		goto tcon_exit;
 	}
 
-	if (rsp->ShareType & SMB2_SHARE_TYPE_DISK)
+	if (rsp->ShareType == SMB2_SHARE_TYPE_DISK) {
 		cifs_dbg(FYI, "connection to disk share\n");
-	else if (rsp->ShareType & SMB2_SHARE_TYPE_PIPE) {
+	} else if (rsp->ShareType == SMB2_SHARE_TYPE_PIPE) {
 		tcon->ipc = true;
 		cifs_dbg(FYI, "connection to pipe share\n");
-	} else if (rsp->ShareType & SMB2_SHARE_TYPE_PRINT) {
+	} else if (rsp->ShareType == SMB2_SHARE_TYPE_PRINT) {
 		tcon->print = true;
 		cifs_dbg(FYI, "connection to printer\n");
 	} else {
-- 
2.9.3

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

* Re: [PATCH] SMB2: Fix share type handling
  2016-11-21 21:53 [PATCH] SMB2: Fix share type handling Christophe JAILLET
@ 2016-11-22  8:19 ` walter harms
  2016-11-22 12:18 ` Aurélien Aptel
  1 sibling, 0 replies; 3+ messages in thread
From: walter harms @ 2016-11-22  8:19 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: sfrench, linux-cifs, samba-technical, linux-kernel, kernel-janitors



Am 21.11.2016 22:53, schrieb Christophe JAILLET:
> In fs/cifs/smb2pdu.h, we have:
> #define SMB2_SHARE_TYPE_DISK    0x01
> #define SMB2_SHARE_TYPE_PIPE    0x02
> #define SMB2_SHARE_TYPE_PRINT   0x03
> 
> Knowing that, with the current code, the SMB2_SHARE_TYPE_PRINT case can
> never trigger and printer share would be interpreted as disk share.
> 
> So, test the ShareType value for equality instead.
> 
> While at it, add some { } to fix a small style issue.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> Compile-tested only.
> 
> The proposed patch changes a bit the semantic as no masking is performed
> anymore. If some upper bits in 'ShareType' are set, it would now be rejected
> instead of silently accepted.
> ---
>  fs/cifs/smb2pdu.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
> index 5ca5ea4668a1..600f52994fd9 100644
> --- a/fs/cifs/smb2pdu.c
> +++ b/fs/cifs/smb2pdu.c
> @@ -1143,12 +1143,12 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree,
>  		goto tcon_exit;
>  	}
>  
> -	if (rsp->ShareType & SMB2_SHARE_TYPE_DISK)
> +	if (rsp->ShareType == SMB2_SHARE_TYPE_DISK) {
>  		cifs_dbg(FYI, "connection to disk share\n");
> -	else if (rsp->ShareType & SMB2_SHARE_TYPE_PIPE) {
> +	} else if (rsp->ShareType == SMB2_SHARE_TYPE_PIPE) {
>  		tcon->ipc = true;
>  		cifs_dbg(FYI, "connection to pipe share\n");
> -	} else if (rsp->ShareType & SMB2_SHARE_TYPE_PRINT) {
> +	} else if (rsp->ShareType == SMB2_SHARE_TYPE_PRINT) {
>  		tcon->print = true;
>  		cifs_dbg(FYI, "connection to printer\n");
>  	} else {


perhaps a switch/case is better suited for this ?
looks more readable.

re,
 wh


switch(sp->ShareType ) {
case SMB2_SHARE_TYPE_DISK:
	cifs_dbg(FYI, "connection to disk share\n");
	break;
case SMB2_SHARE_TYPE_PIPE:
	tcon->ipc = true;
	cifs_dbg(FYI, "connection to pipe share\n");
	break;
case SMB2_SHARE_TYPE_PRINT:
	tcon->ipc = true;
	cifs_dbg(FYI, "connection to printer\n");
	break;
default:

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

* Re: [PATCH] SMB2: Fix share type handling
  2016-11-21 21:53 [PATCH] SMB2: Fix share type handling Christophe JAILLET
  2016-11-22  8:19 ` walter harms
@ 2016-11-22 12:18 ` Aurélien Aptel
  1 sibling, 0 replies; 3+ messages in thread
From: Aurélien Aptel @ 2016-11-22 12:18 UTC (permalink / raw)
  To: Christophe JAILLET, sfrench
  Cc: linux-cifs, samba-technical, linux-kernel, kernel-janitors,
	Christophe JAILLET

Christophe JAILLET <christophe.jaillet@wanadoo.fr> writes:
> Knowing that, with the current code, the SMB2_SHARE_TYPE_PRINT case can
> never trigger and printer share would be interpreted as disk share.

I've checked the SMB2 specs ([MS-SMB2] 3.2.5.5), I can confirm these are
the 3 only options. No upper bits are supposed to be set.

> So, test the ShareType value for equality instead.
>
> While at it, add some { } to fix a small style issue.
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> Compile-tested only.
>
> The proposed patch changes a bit the semantic as no masking is performed
> anymore. If some upper bits in 'ShareType' are set, it would now be rejected
> instead of silently accepted.

The semantic change is correct. I also think a switch would be more
appropriate. Beside this, Looks Good To Me.

-- 
Aurélien Aptel / SUSE Labs Samba Team
GPG: 1839 CB5F 9F5B FB9B AA97  8C99 03C8 A49B 521B D5D3
SUSE Linux GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)

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

end of thread, other threads:[~2016-11-22 12:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-21 21:53 [PATCH] SMB2: Fix share type handling Christophe JAILLET
2016-11-22  8:19 ` walter harms
2016-11-22 12:18 ` Aurélien Aptel

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