diff mbox

cifs: Fix check for regular file in couldbe_mf_symlink()

Message ID 1391178436-10069-1-git-send-email-sprabhu@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Sachin Prabhu Jan. 31, 2014, 2:27 p.m. UTC
MF Symlinks are regular files containing content in a specified format.

The function couldbe_mf_symlink() checks the mode for a set S_IFREG bit
as a test to confirm that it is a regular file. This bit is also set for
other filetypes and simply checking for this bit being set may return
false positives.

We ensure that we are actually checking for a regular file by using the
S_ISREG macro to test instead.

Signed-off-by: Sachin Prabhu <sprabhu@redhat.com>
Reported-by: Neil Brown <neilb@suse.de>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 fs/cifs/link.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jeff Layton Jan. 31, 2014, 2:32 p.m. UTC | #1
On Fri, 31 Jan 2014 14:27:16 +0000
Sachin Prabhu <sprabhu@redhat.com> wrote:

> MF Symlinks are regular files containing content in a specified format.
> 
> The function couldbe_mf_symlink() checks the mode for a set S_IFREG bit
> as a test to confirm that it is a regular file. This bit is also set for
> other filetypes and simply checking for this bit being set may return
> false positives.
> 
> We ensure that we are actually checking for a regular file by using the
> S_ISREG macro to test instead.
> 
> Signed-off-by: Sachin Prabhu <sprabhu@redhat.com>
> Reported-by: Neil Brown <neilb@suse.de>
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  fs/cifs/link.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/cifs/link.c b/fs/cifs/link.c
> index 52f41f9..264ece7 100644
> --- a/fs/cifs/link.c
> +++ b/fs/cifs/link.c
> @@ -185,7 +185,7 @@ format_mf_symlink(u8 *buf, unsigned int buf_len, const char *link_str)
>  bool
>  couldbe_mf_symlink(const struct cifs_fattr *fattr)
>  {
> -	if (!(fattr->cf_mode & S_IFREG))
> +	if (!S_ISREG(fattr->cf_mode))
>  		/* it's not a symlink */
>  		return false;
>  

Looks correct.

Reviewed-by: Jeff Layton <jlayton@redhat.com>
--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Steve French Jan. 31, 2014, 3:07 p.m. UTC | #2
merged into cifs-2.6.git for-next

On Fri, Jan 31, 2014 at 8:32 AM, Jeff Layton <jlayton@redhat.com> wrote:
> On Fri, 31 Jan 2014 14:27:16 +0000
> Sachin Prabhu <sprabhu@redhat.com> wrote:
>
>> MF Symlinks are regular files containing content in a specified format.
>>
>> The function couldbe_mf_symlink() checks the mode for a set S_IFREG bit
>> as a test to confirm that it is a regular file. This bit is also set for
>> other filetypes and simply checking for this bit being set may return
>> false positives.
>>
>> We ensure that we are actually checking for a regular file by using the
>> S_ISREG macro to test instead.
>>
>> Signed-off-by: Sachin Prabhu <sprabhu@redhat.com>
>> Reported-by: Neil Brown <neilb@suse.de>
>> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
>> ---
>>  fs/cifs/link.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/fs/cifs/link.c b/fs/cifs/link.c
>> index 52f41f9..264ece7 100644
>> --- a/fs/cifs/link.c
>> +++ b/fs/cifs/link.c
>> @@ -185,7 +185,7 @@ format_mf_symlink(u8 *buf, unsigned int buf_len, const char *link_str)
>>  bool
>>  couldbe_mf_symlink(const struct cifs_fattr *fattr)
>>  {
>> -     if (!(fattr->cf_mode & S_IFREG))
>> +     if (!S_ISREG(fattr->cf_mode))
>>               /* it's not a symlink */
>>               return false;
>>
>
> Looks correct.
>
> Reviewed-by: Jeff Layton <jlayton@redhat.com>
diff mbox

Patch

diff --git a/fs/cifs/link.c b/fs/cifs/link.c
index 52f41f9..264ece7 100644
--- a/fs/cifs/link.c
+++ b/fs/cifs/link.c
@@ -185,7 +185,7 @@  format_mf_symlink(u8 *buf, unsigned int buf_len, const char *link_str)
 bool
 couldbe_mf_symlink(const struct cifs_fattr *fattr)
 {
-	if (!(fattr->cf_mode & S_IFREG))
+	if (!S_ISREG(fattr->cf_mode))
 		/* it's not a symlink */
 		return false;