Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace UAPI one-element arrays with flexible-array members #113

Closed
7 tasks done
GustavoARSilva opened this issue Oct 28, 2020 · 4 comments
Closed
7 tasks done

Replace UAPI one-element arrays with flexible-array members #113

GustavoARSilva opened this issue Oct 28, 2020 · 4 comments
Assignees
Labels
compiler Needs compiler support [Idiom] fake flexible array [Linux] v6.12 Released in Linux kernel v6.12 [PATCH] Submitted A patch has been submitted upstream UAPI UAPI changes are needed

Comments

@GustavoARSilva
Copy link
Collaborator

GustavoARSilva commented Oct 28, 2020

There are currently 7 files containing one-element arrays in UAPI:

  • include/uapi/linux/in.h commit 5854a09
  • include/uapi/xen/gntalloc.h https://lore.kernel.org/lkml/[email protected]
  • false positive include/uapi/linux/netfilter/nf_nat.h
  • false positive include/uapi/linux/videodev2.h
  • false positive include/uapi/linux/coff.h
  • include/uapi/linux/isst_if.h
    • these are not actually being addressed by the kernel
  • include/uapi/scsi/fc/fc_els.h commit 94dfc73
@GustavoARSilva GustavoARSilva added compiler Needs compiler support [Refactor] 1-element array Conversion away from one-element array labels Oct 28, 2020
@GustavoARSilva GustavoARSilva self-assigned this Oct 28, 2020
@GustavoARSilva
Copy link
Collaborator Author

GustavoARSilva commented Oct 29, 2020

Apparently, the one-element arrays in include/uapi/linux/videodev2.h are merely placeholders for alignment, and are not being used as variable-length arrays:

 950 struct v4l2_requestbuffers {                                                                        
 951         __u32                   count;                                                              
 952         __u32                   type;           /* enum v4l2_buf_type */                            
 953         __u32                   memory;         /* enum v4l2_memory */                              
 954         __u32                   capabilities;                                                       
 955         __u32                   reserved[1];                                                        
 956 };

1722 struct v4l2_ext_control {                                                                           
1723         __u32 id;                                                                                   
1724         __u32 size;                                                                                 
1725         __u32 reserved2[1];                                                                         
1726         union {                                                                                     
1727                 __s32 value;                                                                        
1728                 __s64 value64;                                                                      
1729                 char __user *string;                                                                
1730                 __u8 __user *p_u8;                                                                  
1731                 __u16 __user *p_u16;                                                                
1732                 __u32 __user *p_u32;                                                                
1733                 struct v4l2_area __user *p_area;                                                    
1734                 void __user *ptr;                                                                   
1735         };                                                                                          
1736 } __attribute__ ((packed));

1738 struct v4l2_ext_controls {                                                                          
1739         union {                                                                                     
1740 #ifndef __KERNEL__                                                                                  
1741                 __u32 ctrl_class;                                                                   
1742 #endif                                                                                              
1743                 __u32 which;                                                                        
1744         };                                                                                          
1745         __u32 count;                                                                                
1746         __u32 error_idx;                                                                            
1747         __s32 request_fd;                                                                           
1748         __u32 reserved[1];                                                                          
1749         struct v4l2_ext_control *controls;                                                          
1750 };

@GustavoARSilva GustavoARSilva added the UAPI UAPI changes are needed label Nov 2, 2020
@kees
Copy link

kees commented Jan 13, 2021

It's non-trivial to update UAPI headers, so to eliminate one-element arrays, it's likely that anonymous unions need to be used. There are some caveats with that, though:

https://www.mail-archive.com/[email protected]/msg48095.html

@kees kees added [Idiom] fake flexible array and removed [Refactor] 1-element array Conversion away from one-element array labels Sep 16, 2021
@kees kees added the [PATCH] Submitted A patch has been submitted upstream label Feb 6, 2024
staging-kernelci-org pushed a commit to kernelci/linux that referenced this issue Feb 14, 2024
Without changing the structure size (since it is UAPI), add a proper
flexible array member, and reference it in the kernel so that it will
not be trip the array-bounds sanitizer[1].

Link: KSPP#113 [1]
Cc: Juergen Gross <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Oleksandr Tyshchenko <[email protected]>
Cc: Gustavo A. R. Silva <[email protected]>
Cc: [email protected]
Signed-off-by: Kees Cook <[email protected]>
Reviewed-by: Gustavo A. R. Silva <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Juergen Gross <[email protected]>
rohanmclure pushed a commit to rohanmclure/linux-ci that referenced this issue Mar 7, 2024
Without changing the structure size (since it is UAPI), add a proper
flexible array member, and reference it in the kernel so that it will
not be trip the array-bounds sanitizer[1].

Link: KSPP/linux#113 [1]
Cc: Juergen Gross <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Oleksandr Tyshchenko <[email protected]>
Cc: Gustavo A. R. Silva <[email protected]>
Cc: [email protected]
Signed-off-by: Kees Cook <[email protected]>
Reviewed-by: Gustavo A. R. Silva <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Juergen Gross <[email protected]>
@kees kees added the [Linux] v6.12 Released in Linux kernel v6.12 label Aug 23, 2024
@kees
Copy link

kees commented Aug 23, 2024

All the UAPI 1-element arrays used as flexible arrays have been refactored.

@kees kees closed this as completed Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler Needs compiler support [Idiom] fake flexible array [Linux] v6.12 Released in Linux kernel v6.12 [PATCH] Submitted A patch has been submitted upstream UAPI UAPI changes are needed
Projects
None yet
Development

No branches or pull requests

2 participants