Skip to contentSkip to conversation

ALSA: seq: Fix snd_seq_expand_var_event() call to user-space

PATCH Superseded Takashi Iwai 2 participants 4 messages Sep 5, 2023 Sound

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: seq: Fix snd_seq_expand_var_event() call to user-space

The recent fix to clear the padding bytes at snd_seq_expand_var_event() broke the read to user-space with in_kernel=0 parameter. For user-space address, it has to use clear_user() instead of memset().

Fixes f80e6d60d677 ("ALSA: seq: Clear padded bytes at expanding events")
Reported-and-tested-by Ash Holland <[email protected]>
---
 sound/core/seq/seq_memory.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
sound/core/seq/seq_memory.c +6 -2
index 174585bf59d2..94db3726864b 100644
@@ -187,8 +187,12 @@ int snd_seq_expand_var_event(const struct snd_seq_event *event, int count, char
 	err = expand_var_event(event, 0, len, buf, in_kernel);
 	if (err < 0)
 		return err;
-	if (len != newlen)
-		memset(buf + len, 0, newlen - len);
+	if (len != newlen) {
+		if (in_kernel)
+			memset(buf + len, 0, newlen - len);
+		else
+			clear_user((__force void __user *)buf + len, newlen - len);
+	}
 	return newlen;
 }
 EXPORT_SYMBOL(snd_seq_expand_var_event);
Signature · 1 line
2.35.3
#1 lore raw
kernel test robot noticed the following build warnings:

Hi Takashi,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.5 next-20230905]
[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/Takashi-Iwai/ALSA-seq-Fix-snd_seq_expand_var_event-call-to-user-space/20230905-132920
base:   linus/master
patch link:    https://lore.kernel.org/r/20230905052631.18240-1-tiwai%40suse.de
patch subject: [PATCH] ALSA: seq: Fix snd_seq_expand_var_event() call to user-space
config: sparc64-defconfig (https://download.01.org/0day-ci/archive/20230905/[email protected]/config)
compiler: sparc64-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230905/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

In file included from arch/sparc/include/asm/uaccess.h:8,
from include/linux/uaccess.h:11,
from include/linux/sched/task.h:11,
from include/linux/sched/signal.h:9, from sound/core/seq/seq_memory.c:12:
sound/core/seq/seq_memory.c: In function 'snd_seq_expand_var_event':

>> arch/sparc/include/asm/uaccess_64.h:243:20: warning: ignoring return value of '__clear_user' declared with attribute 'warn_unused_result' [-Wunused-result]
     243 | #define clear_user __clear_user
   sound/core/seq/seq_memory.c:194:25: note: in expansion of macro 'clear_user'
     194 |                         clear_user((__force void __user *)buf + len, newlen - len);
         |                         ^~~~~~~~~~

vim +243 arch/sparc/include/asm/uaccess_64.h

f5e706ad886b6a include/asm-sparc/uaccess_64.h Sam Ravnborg 2008-07-17 242
f5e706ad886b6a include/asm-sparc/uaccess_64.h Sam Ravnborg 2008-07-17 @243 #define clear_user __clear_user f5e706ad886b6a include/asm-sparc/uaccess_64.h Sam Ravnborg 2008-07-17 244

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#2 lore raw
In reply to Takashi Iwai
kernel test robot noticed the following build warnings:

Hi Takashi,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.5 next-20230905]
[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/Takashi-Iwai/ALSA-seq-Fix-snd_seq_expand_var_event-call-to-user-space/20230905-132920
base:   linus/master
patch link:    https://lore.kernel.org/r/20230905052631.18240-1-tiwai%40suse.de
patch subject: [PATCH] ALSA: seq: Fix snd_seq_expand_var_event() call to user-space
config: arm-randconfig-r014-20230905 (https://download.01.org/0day-ci/archive/20230905/[email protected]/config)
compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230905/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> sound/core/seq/seq_memory.c:194:4: warning: ignoring return value of function declared with 'warn_unused_result' attribute [-Wunused-result]
     194 |                         clear_user((__force void __user *)buf + len, newlen - len);
         |                         ^~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1 warning generated.

vim +/warn_unused_result +194 sound/core/seq/seq_memory.c

173
174 int snd_seq_expand_var_event(const struct snd_seq_event *event, int count, char *buf,
175 int in_kernel, int size_aligned)
176 {
177 int len, newlen, err;
178
179 len = get_var_len(event);
180 if (len < 0)
181 return len;
182 newlen = len;
183 if (size_aligned > 0)
184 newlen = roundup(len, size_aligned);
185 if (count < newlen)
186 return -EAGAIN;
187 err = expand_var_event(event, 0, len, buf, in_kernel);
188 if (err < 0)
189 return err;
190 if (len != newlen) {
191 if (in_kernel)
192 memset(buf + len, 0, newlen - len);
193 else

 > 194				clear_user((__force void __user *)buf + len, newlen - len);

195 }
196 return newlen;
197 }
198 EXPORT_SYMBOL(snd_seq_expand_var_event);
199

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#3 lore raw
In reply to Takashi Iwai
kernel test robot noticed the following build warnings:

Hi Takashi,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.5 next-20230905]
[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/Takashi-Iwai/ALSA-seq-Fix-snd_seq_expand_var_event-call-to-user-space/20230905-132920
base:   linus/master
patch link:    https://lore.kernel.org/r/20230905052631.18240-1-tiwai%40suse.de
patch subject: [PATCH] ALSA: seq: Fix snd_seq_expand_var_event() call to user-space
config: parisc-allyesconfig (https://download.01.org/0day-ci/archive/20230905/[email protected]/config)
compiler: hppa-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230905/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

In file included from include/linux/uaccess.h:11,
from include/linux/sched/task.h:11,
from include/linux/sched/signal.h:9, from sound/core/seq/seq_memory.c:12:
sound/core/seq/seq_memory.c: In function 'snd_seq_expand_var_event':

>> arch/parisc/include/asm/uaccess.h:208:20: warning: ignoring return value of 'lclear_user' declared with attribute 'warn_unused_result' [-Wunused-result]
     208 | #define clear_user lclear_user
   sound/core/seq/seq_memory.c:194:25: note: in expansion of macro 'clear_user'
     194 |                         clear_user((__force void __user *)buf + len, newlen - len);
         |                         ^~~~~~~~~~

vim +208 arch/parisc/include/asm/uaccess.h

^1da177e4c3f41 include/asm-parisc/uaccess.h      Linus Torvalds  2005-04-16  195  
^1da177e4c3f41 include/asm-parisc/uaccess.h      Linus Torvalds  2005-04-16  196  
^1da177e4c3f41 include/asm-parisc/uaccess.h      Linus Torvalds  2005-04-16  197  /*
^1da177e4c3f41 include/asm-parisc/uaccess.h      Linus Torvalds  2005-04-16  198   * Complex access routines -- external declarations
^1da177e4c3f41 include/asm-parisc/uaccess.h      Linus Torvalds  2005-04-16  199   */
^1da177e4c3f41 include/asm-parisc/uaccess.h      Linus Torvalds  2005-04-16  200  
b1195c0e3ee1a1 arch/parisc/include/asm/uaccess.h James Bottomley 2012-05-26  201  extern long strncpy_from_user(char *, const char __user *, long);
671028728083e8 arch/parisc/include/asm/uaccess.h Helge Deller    2021-09-09  202  extern __must_check unsigned lclear_user(void __user *, unsigned long);
1260dea6d2eb75 arch/parisc/include/asm/uaccess.h Helge Deller    2021-09-04  203  extern __must_check long strnlen_user(const char __user *src, long n);
^1da177e4c3f41 include/asm-parisc/uaccess.h      Linus Torvalds  2005-04-16  204  /*
^1da177e4c3f41 include/asm-parisc/uaccess.h      Linus Torvalds  2005-04-16  205   * Complex access routines -- macros
^1da177e4c3f41 include/asm-parisc/uaccess.h      Linus Torvalds  2005-04-16  206   */
^1da177e4c3f41 include/asm-parisc/uaccess.h      Linus Torvalds  2005-04-16  207  
^1da177e4c3f41 include/asm-parisc/uaccess.h      Linus Torvalds  2005-04-16 @208  #define clear_user lclear_user
^1da177e4c3f41 include/asm-parisc/uaccess.h      Linus Torvalds  2005-04-16  209  #define __clear_user lclear_user
^1da177e4c3f41 include/asm-parisc/uaccess.h      Linus Torvalds  2005-04-16  210  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki