net/atm: fix proc_mpc_write 1 byte less calculated

Message ID 20221013151901.29368-1-cppcoffee@gmail.com
State New
Headers
Series net/atm: fix proc_mpc_write 1 byte less calculated |

Commit Message

Xiaobo Liu Oct. 13, 2022, 3:19 p.m. UTC
  Then the input contains '\0' or '\n', proc_mpc_write has read them,
so the return value needs +1.

Signed-off-by: Xiaobo Liu <cppcoffee@gmail.com>
---
 net/atm/mpoa_proc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
  

Comments

Eric Dumazet Oct. 13, 2022, 3:37 p.m. UTC | #1
On Thu, Oct 13, 2022 at 8:19 AM Xiaobo Liu <cppcoffee@gmail.com> wrote:
>
> Then the input contains '\0' or '\n', proc_mpc_write has read them,
> so the return value needs +1.
>
> Signed-off-by: Xiaobo Liu <cppcoffee@gmail.com>
> ---
>  net/atm/mpoa_proc.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/net/atm/mpoa_proc.c b/net/atm/mpoa_proc.c
> index 829db9eba..444ceda60 100755
> --- a/net/atm/mpoa_proc.c
> +++ b/net/atm/mpoa_proc.c
> @@ -224,8 +224,11 @@ static ssize_t proc_mpc_write(struct file *file, const char __user *buff,
>                         free_page((unsigned long)page);
>                         return -EFAULT;
>                 }
> -               if (*p == '\0' || *p == '\n')
> +
> +               if (*p == '\0' || *p == '\n') {
> +                       len += 1
>                         break;
> +               }
>         }
>
>         *p = '\0';
> --
> 2.21.0 (Apple Git-122.2)
>

Hi Xiaobo

Can you submit a v2, with this added tag ?

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")

Also, I would switch to something cleaner like

diff --git a/net/atm/mpoa_proc.c b/net/atm/mpoa_proc.c
index 829db9eba0cb95ac9cfe775e8eaad712943a8dbe..df530e9725fa63820a7adcd44e750db0733f9d94
100644
--- a/net/atm/mpoa_proc.c
+++ b/net/atm/mpoa_proc.c
@@ -219,11 +219,12 @@ static ssize_t proc_mpc_write(struct file *file,
const char __user *buff,
        if (!page)
                return -ENOMEM;

-       for (p = page, len = 0; len < nbytes; p++, len++) {
+       for (p = page, len = 0; len < nbytes; p++) {
                if (get_user(*p, buff++)) {
                        free_page((unsigned long)page);
                        return -EFAULT;
                }
+               len++;
                if (*p == '\0' || *p == '\n')
                        break;
        }
  
kernel test robot Oct. 13, 2022, 8:13 p.m. UTC | #2
Hi Xiaobo,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on net-next/master]
[also build test ERROR on net/master linus/master v6.0 next-20221013]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Xiaobo-Liu/net-atm-fix-proc_mpc_write-1-byte-less-calculated/20221013-232130
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 0326074ff4652329f2a1a9c8685104576bd8d131
config: i386-randconfig-a013
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/a873bf31a6f0de49f99feab479736ec2555de73b
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Xiaobo-Liu/net-atm-fix-proc_mpc_write-1-byte-less-calculated/20221013-232130
        git checkout a873bf31a6f0de49f99feab479736ec2555de73b
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash net/atm/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> net/atm/mpoa_proc.c:229:12: error: expected ';' after expression
                           len += 1
                                   ^
                                   ;
   1 error generated.


vim +229 net/atm/mpoa_proc.c

   205	
   206	static ssize_t proc_mpc_write(struct file *file, const char __user *buff,
   207				      size_t nbytes, loff_t *ppos)
   208	{
   209		char *page, *p;
   210		unsigned int len;
   211	
   212		if (nbytes == 0)
   213			return 0;
   214	
   215		if (nbytes >= PAGE_SIZE)
   216			nbytes = PAGE_SIZE-1;
   217	
   218		page = (char *)__get_free_page(GFP_KERNEL);
   219		if (!page)
   220			return -ENOMEM;
   221	
   222		for (p = page, len = 0; len < nbytes; p++, len++) {
   223			if (get_user(*p, buff++)) {
   224				free_page((unsigned long)page);
   225				return -EFAULT;
   226			}
   227	
   228			if (*p == '\0' || *p == '\n') {
 > 229				len += 1
   230				break;
   231			}
   232		}
   233	
   234		*p = '\0';
   235	
   236		if (!parse_qos(page))
   237			printk("mpoa: proc_mpc_write: could not parse '%s'\n", page);
   238	
   239		free_page((unsigned long)page);
   240	
   241		return len;
   242	}
   243
  
kernel test robot Oct. 13, 2022, 8:23 p.m. UTC | #3
Hi Xiaobo,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on net-next/master]
[also build test ERROR on net/master linus/master v6.0 next-20221013]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Xiaobo-Liu/net-atm-fix-proc_mpc_write-1-byte-less-calculated/20221013-232130
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 0326074ff4652329f2a1a9c8685104576bd8d131
config: openrisc-randconfig-r035-20221012
compiler: or1k-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/a873bf31a6f0de49f99feab479736ec2555de73b
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Xiaobo-Liu/net-atm-fix-proc_mpc_write-1-byte-less-calculated/20221013-232130
        git checkout a873bf31a6f0de49f99feab479736ec2555de73b
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=openrisc SHELL=/bin/bash net/atm/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   net/atm/mpoa_proc.c: In function 'proc_mpc_write':
>> net/atm/mpoa_proc.c:229:33: error: expected ';' before 'break'
     229 |                         len += 1
         |                                 ^
         |                                 ;
     230 |                         break;
         |                         ~~~~~    


vim +229 net/atm/mpoa_proc.c

   205	
   206	static ssize_t proc_mpc_write(struct file *file, const char __user *buff,
   207				      size_t nbytes, loff_t *ppos)
   208	{
   209		char *page, *p;
   210		unsigned int len;
   211	
   212		if (nbytes == 0)
   213			return 0;
   214	
   215		if (nbytes >= PAGE_SIZE)
   216			nbytes = PAGE_SIZE-1;
   217	
   218		page = (char *)__get_free_page(GFP_KERNEL);
   219		if (!page)
   220			return -ENOMEM;
   221	
   222		for (p = page, len = 0; len < nbytes; p++, len++) {
   223			if (get_user(*p, buff++)) {
   224				free_page((unsigned long)page);
   225				return -EFAULT;
   226			}
   227	
   228			if (*p == '\0' || *p == '\n') {
 > 229				len += 1
   230				break;
   231			}
   232		}
   233	
   234		*p = '\0';
   235	
   236		if (!parse_qos(page))
   237			printk("mpoa: proc_mpc_write: could not parse '%s'\n", page);
   238	
   239		free_page((unsigned long)page);
   240	
   241		return len;
   242	}
   243
  

Patch

diff --git a/net/atm/mpoa_proc.c b/net/atm/mpoa_proc.c
index 829db9eba..444ceda60 100755
--- a/net/atm/mpoa_proc.c
+++ b/net/atm/mpoa_proc.c
@@ -224,8 +224,11 @@  static ssize_t proc_mpc_write(struct file *file, const char __user *buff,
 			free_page((unsigned long)page);
 			return -EFAULT;
 		}
-		if (*p == '\0' || *p == '\n')
+
+		if (*p == '\0' || *p == '\n') {
+			len += 1
 			break;
+		}
 	}
 
 	*p = '\0';