Linux 6.8: Use roken's strlcpy() in kernel module The Linux 6.8 commit 'string: Remove strlcpy()' (d26270061a) removed the the strlcpy function from the Linux kernel. The replacement function, strscpy(), cannot be used as a drop-in replacement as its currently a Linux kernel specific function and there are differences in the returned value. We can use roken's strlcpy() (provided in roken/strlcpy.c). Create a configure test to that defines its own strlcpy() to test if the kernel doesn't provide one itself. Note, we need to use a different function signature for strlcpy() from what the kernel might have otherwise the test build succeeds when the kernel does provide a strlcpy(). Update the OpenAFS kernel specific roken.h to define the prototype for strlcpy when it's not present in the Linux kernel. We need to match the defines used in the 'real' roken.h so the roken/strlcpy.c can build properly. Add defines for ROKEN_LIB_FUNCTION, ROKEN_LIB_CALL and ROKEN_LIB_VARIABLE to the kernel roken.h Update Linux's osi_machdep.h to include roken.h so the strlcpy protoype is available. Update the Linux MakefileProto to include the strcpy-kernel object when building the kernel module. Change-Id: I64a5743ba94134538853f51cd6e7a8df19127624 Reviewed-on: https://gerrit.openafs.org/15646 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Linux 6.8: Remove ctl_table sentinels The Linux 6.8 commit 'sysctl: Remove the now superfluous sentinel elements from ctl_table array' (c8a65501d3) was a clean up commit that removed the sentinel entry in the ctl_table array (e.g. the "null" entry at the end of the table). As of Linux 6.8, including the sentinel entry (.procname =) in the ctl_table is unnecessary, but doesn't yet break anything. But it is likely that including the sentinel will start to cause runtime errors in future Linux versions very soon, so avoid the sentinel when we can, to avoid possible problems in the future. Define a new macro that can be used as the last entry of a ctl_table that will either add a "null" entry, or nothing. There is not a specific build test we can use within configure, so we must explicitly test the Linux version to decide if we need to use a sentinel or not when defining the macro. We are selecting 6.8 to match the version where the Linux kernel is removing the sentinels from the in kernel filesystems. Note: See the Linux merge commits 'Merge tag 'sysctl-6.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux' (a05aea98d4) for more details behind the staged removal of the sentinels in the ctl_table structures and the potential future change for removing the actual check for the sentinel within the Linux kernel. Change-Id: I0f50872e7d08dc198584623337909a180002ab30 Reviewed-on: https://gerrit.openafs.org/15645 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Mark Vitale <mvitale@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Linux 6.8: use hlist iteration for dentry children Linux 6.8 commit 'dentry: switch the lists of children to hlist' (da549bdd15) replaces the dentry lists d_subdirs/d_child with the hlist d_children/d_sib. Add an autoconf test for a d_children member in the dentry structure. Define a macro that uses the applicable Linux function for iterating over a dentry's children. Change-Id: I6e8fb9a58c0afd9c383c07c294f64df1fc045585 Reviewed-on: https://gerrit.openafs.org/15632 Reviewed-by: Andrew Deason <adeason@sinenomine.net> Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Mark Vitale <mvitale@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
afs: Add static attribute to internal functions When building against a Linux 6.8 kernel, functions that are missing prototypes or declarations are flagged. We can add the static attribute to functions that are not referenced outside of the file that implements them to avoid having these functions flagged by the compiler. These functions are flagged due to missing prototypes when building against a Linux 6.8 kernel (which sets the -Wmissing-declarations and -Wmissing-prototypes compiler flags as default). Linux 6.8 commit: 'Makefile.extrawarn: turn on missing-prototypes globally' (0fcb70851f). When building against a kernel with CONFIG_WERROR=y, the build fails. There are no functional changes in this commit. Change-Id: I24c78a3167f6a81da4f62267cf901024468ae6b3 Reviewed-on: https://gerrit.openafs.org/15625 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
afs: fix 'ops' variable may be used uninitialized When the function rxfs_storeInit() has the static attribute, gcc flags the variable 'ops' as possibly uninitialized. In function 'afs_CacheStoreDCaches', inlined from 'afs_CacheStoreVCache' at .../src/afs/afs_fetchstore.c:630:14: .../afs/afs_fetchstore.c:535:17: error: 'ops' may be used uninitialized [-Werror=maybe-uninitialized] 535 | code = (*ops->destroy)(&rock, code); | ~^~~~~~~~~~~~~~ ...src/afs/afs_fetchstore.c: In function 'afs_CacheStoreVCache': ...src/afs/afs_fetchstore.c:567:22: note: 'ops' was declared here 567 | struct storeOps *ops; | ^~~ cc1: all warnings being treated as errors This is a false positive report by the gcc compiler. The function rxfs_storeInit() returns a 0 only when it has successfully assigned a value to the ops variable, and afs_CacheStoreDcaches() is only called if the return value from rxfs_storeInit() is 0. The ops variable is only used within a block that is within a for loop, which could leave a stray value if the variable isn't initialized within that loop. Assigning a NULL to ops is sufficient to avoid the compiler error, and relocating the declaration of the ops variable into the block where it is actually used ensures that it's always initialized before its use within the loop. Clean up whitespace in the statement that follows the new location for the ops variable. Note, this commit is being added before a commit that adds the static attribute to the rxfs_storeInit() function which also "fixes" the compiler error (see: afs: Add static attribute to internal functions). Change-Id: Id2c3e68720f92ea05818419567ffe90ce0b5061a Reviewed-on: https://gerrit.openafs.org/15630 Reviewed-by: Andrew Deason <adeason@sinenomine.net> Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Mark Vitale <mvitale@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
afs: Remove SRXAFSCB* protos from afs_prototypes.h The prototypes for the afscbint RPC functions (SRXAFSCB_*) implemented in afs_callback.c are defined in 2 locations, afs_protypes.h and afscbint.h (which is generated by rxgen). Remove the protoypes for the SRXAFSCB_* functions from afs_prototypes.h as they are redundant and are currently out of sync (the prototypes for SRXAFSCB_GetCellByNum() and SRXAFSCB_TellMeAboutYourself() are not present in afs_prototypes.h). Also remove a redundant prototype for afs_RXCallBackServer() which was prototyped both before and in the middle of the SRXAFSCB* prototypes. Since afs_callback.c only pulled in afs_prototypes.h and not afscbint.h, add an include for afscbint.h to ensure that the all the prototypes for the SRXAFSCB_* functions are present. The 2 functions listed above are flagged due to missing prototypes when building against a Linux 6.8 kernel (which sets the -Wmissing-declarations and -Wmissing-prototypes compiler flags as default). Linux 6.8 commit: 'Makefile.extrawarn: turn on missing-prototypes globally' (0fcb70851f). When building against a kernel with CONFIG_WERROR=y, the build fails. Change-Id: Ieb43314cbeef444d44a3af74b4dca7a7986b54ba Reviewed-on: https://gerrit.openafs.org/15644 Reviewed-by: Mark Vitale <mvitale@sinenomine.net> Tested-by: Benjamin Kaduk <kaduk@mit.edu> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
afs: Add afs_xioctl prototyes to afs_prototypes.h Several .c files have external function prototypes for the afs_xioctl function, while the implementing files do not have the prototype. Move these prototypes into afs_prototypes.h so that the prototypes are available to both the caller and the implementation. Because the file holding the implementation does not have a prototypes, afs_xioctl() is being flagged when building against a Linux 6.8 kernel (which sets the -Wmissing-declarations and -Wmissing-prototypes compiler flags as default). Linux 6.8 commit: 'Makefile.extrawarn: turn on missing-prototypes globally' (0fcb70851f). When building against a Linux kernel with CONFIG_WERROR=y, the build fails. Note that the function afs_xioctl() has platform specific implementations. Change-Id: I0956daace8c9036a924b928e387eb4a2ea542bf1 Reviewed-on: https://gerrit.openafs.org/15643 Reviewed-by: Andrew Deason <adeason@sinenomine.net> Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Mark Vitale <mvitale@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
afs: Move function prototypes into headers Several .c files contain external function prototypes, while the implementing files do not have these prototypes. Move these prototypes into header files so that the prototypes are available to both the caller and the implementation. Because the file holding the implementation does not have prototypes, these functions are flagged when building against a Linux 6.8 kernel (which sets the -Wmissing-declarations and -Wmissing-prototypes compiler flags as default). Linux 6.8 commit: 'Makefile.extrawarn: turn on missing-prototypes globally' (0fcb70851f). When building against a kernel with CONFIG_WERROR=y, the build fails. Add the prototypes for the following to afs_prototypes.h: exporter_add afs_syscall (AFS_LINUX_ENV) BlobScan Remove the prototypes from the .c files where they are referenced. Change-Id: Ifc75cafe0132bb4cb8714062253f08874be7c06d Reviewed-on: https://gerrit.openafs.org/15642 Reviewed-by: Andrew Deason <adeason@sinenomine.net> Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Mark Vitale <mvitale@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
afs: Add includes to pick up function prototypes The functions defined in LINUX/osi_crypto.c, osi_pagecopy.c, osi_probe.c, and osi_syscall.c have function prototypes defined in existing header files, however either due to missing includes or preprocessor conditionals that skip the includes, these function prototypes are not being pulled in. These functions are flagged due to missing prototypes when building against a Linux 6.8 kernel (which sets the -Wmissing-declarations and -Wmissing-prototypes compiler flags as default). Linux 6.8 commit: 'Makefile.extrawarn: turn on missing-prototypes globally' (0fcb70851f). When building against a kernel with CONFIG_WERROR=y, the build fails. Add the necessary includes to osi_crypto.c and osi_pagecopy.c and re-arrange the includes in osi_probe.c and osi_syscall.c to ensure that the function prototypes are present when building the Linux kernel module. Change-Id: Idcb409b1c25354b1b8b3bff286000a189651bbf6 Reviewed-on: https://gerrit.openafs.org/15641 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Andrew Deason <adeason@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
afs: Declare init_hckernel_mutex() The function init_hckernel_mutex() (in rand.c) is flagged due to a missing prototype when building against a Linux 6.8 kernel (which sets the -Wmissing-declarations and -Wmissing-prototypes compiler flags as default). Linux 6.8 commit: 'Makefile.extrawarn: turn on missing-prototypes globally' (0fcb70851f). When building against a kernel with CONFIG_WERROR=y, the build fails. Add a function prototype for init_hckernel_mutex() to afs_osi.h and remove the prototype from afs_osi.c There are no functional changes with this commit. Change-Id: Iaecfc3fa4d341ed784a28f4d9d0665a13fef7995 Reviewed-on: https://gerrit.openafs.org/15622 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Andrew Deason <adeason@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
afs: Remove afs_DbgDisconFiles() The function afs_DbgDisconFiles() is not referenced anywhere within the source tree. Remove the function afs_DbgDisconFiles(). The commit: 'disconnected-rw-20080922' (433afd4779) introduced afs_DbgDisconFiles(), but the function was never used. This function is flagged due to a missing prototype when building against a Linux 6.8 kernel (which sets the -Wmissing-declarations and -Wmissing-prototypes compiler flags as default). Linux 6.8 commit: 'Makefile.extrawarn: turn on missing-prototypes globally' (0fcb70851f). When building against a kernel with CONFIG_WERROR=y, the build fails. Change-Id: Ib28eb6a167c6add2639f5db0dee8709465b02909 Reviewed-on: https://gerrit.openafs.org/15640 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Andrew Deason <adeason@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
afs: Remove SRXAFSCB_FetchData/StoreData Commit 'client-64bit-file-size-support-20011031' (971b18bc42) introduced the RPC functions SRXAFSCB_FetchData() and SRXAFSCB_StoreData with RPC numbers of 65536 and 65537 respectively. Commit 'more-64bit-file-size-support-20011031' (c5b1a3775f) removed the references from afscbint.xg, but did not remove the actual code. The 65536 RPC number was reassigned to SRXAFSCB_GetCE64, and the commit: 'This is mostly a rewrite of src/afs/afs_cell.c, and associated changes' (629d08065) assigned the 65537 RPC to SRXAFSCB_GetCellByNum. Remove the 2 functions since there are no references other than the prototype in afs_prototypes.h. This function is flagged due to a missing prototype when building against a Linux 6.8 kernel (which sets the -Wmissing-declarations and -Wmissing-prototypes compiler flags as default). Linux 6.8 commit: 'Makefile.extrawarn: turn on missing-prototypes globally' (0fcb70851f). Change-Id: I07eff531fc0b17f750eb69e7ac197ff4cebcd5d5 Reviewed-on: https://gerrit.openafs.org/15639 Reviewed-by: Andrew Deason <adeason@sinenomine.net> Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
afs: Remove dummy_PSetAcl() The function dummy_PSetAcl() is not referenced anywhere within the source tree. Remove the function dummy_PSetAcl(). The commit: 'doxygen-comments-20081010' (4b72f8765c) introduced the function, but dummy_PSetAcl() has never been referenced or defined within a header file. This function is flagged due to a missing prototype when building against a Linux 6.8 kernel (which sets the -Wmissing-declarations and -Wmissing-prototypes compiler flags as default). Linux 6.8 commit: 'Makefile.extrawarn: turn on missing-prototypes globally' (0fcb70851f). When building against a kernel with CONFIG_WERROR=y, the build fails. Change-Id: Icba0b52335aa5b5983858a8a1964a092e016ccea Reviewed-on: https://gerrit.openafs.org/15618 Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: Benjamin Kaduk <kaduk@mit.edu>
afs: Remove afs_osi_UnmaskUserLoop() The function afs_osi_UnmaskUserLoop() is not referenced anywhere within the source tree. Remove the function afs_osi_UnmaskUserLoop(). The commit: 'darwin-afsdb-handler-signal-mask-20040728' (9728182c00) introduced the function, but afs_osi_UnmaskUserLoop() has never been referenced or defined within a header file. This function is flagged due to a missing prototype when building against a Linux 6.8 kernel (which sets the -Wmissing-declarations and -Wmissing-prototypes compiler flags as default). Linux 6.8 commit: 'Makefile.extrawarn: turn on missing-prototypes globally' (0fcb70851f). When building against a kernel with CONFIG_WERROR=y, the build fails. Change-Id: Ie6a4c9293d612baea1df90bf12a75391d7824603 Reviewed-on: https://gerrit.openafs.org/15617 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Andrew Deason <adeason@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
afs: Remove afs_MemExtendEntry() The function afs_MemExtendEntry() is not referenced anywhere within the source tree. Remove the function afs_MemExtendEntry(). The commit: 'memcache: add extend-entry function' (f821c7e5c8) introduced the function, but afs_MemExtendEntry() has never been referenced or defined within a header file. This function is flagged due to a missing prototype when building against a Linux 6.8 kernel (which sets the -Wmissing-declarations and -Wmissing-prototypes compiler flags as default). Linux 6.8 commit: 'Makefile.extrawarn: turn on missing-prototypes globally' (0fcb70851f). When building against a kernel with CONFIG_WERROR=y, the build fails. Note, afsMemExtendedEntry() was a wrapper for the function _afs_MemExtendedEntry(), which is still used. Change-Id: Id4911a91af6d95eec037d83fff500546be85aa7f Reviewed-on: https://gerrit.openafs.org/15616 Tested-by: Benjamin Kaduk <kaduk@mit.edu> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
afs: Remove DFlushDCache() The function DFlushDcache() is not referenced anywhere within the source tree. Remove the function DFlushDCache(). The commit: 'disconnected-shadow-directory-fixes-20090121' (4045f3d535) removed the code reference to DFlushDCache() and the commit: "dir: Prototype and function name cleanup" (5ad1e6cb90) removed the function prototype. The function was introduced in the commit: "disconnected-flush-before-shadowing-20090119" (e1cc987ea5). This function is flagged due to a missing prototype when building against a Linux 6.8 kernel (which sets the -Wmissing-declarations and -Wmissing-prototypes compiler flags as default). Linux 6.8 commit: "Makefile.extrawarn: turn on missing-prototypes globally" (0fcb70851f). When building against a kernel with CONFIG_WERROR=y, the build fails. Change-Id: I2e8e7588c13459fe5695c68bdc031d246258e6fa Reviewed-on: https://gerrit.openafs.org/15615 Tested-by: Benjamin Kaduk <kaduk@mit.edu> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Linux 6.7: convert to inode a/mtime accessor funcs The Linux 6.7 commit "fs: new accessor methods for atime and mtime" (077c212f03) is a follow up to the Linux 6.6 commit "fs: add ctime accessors infrastructure" (9b6304c1d5) With the above 6.7 commit, the inode's i_atime and i_mtime are renamed to __i_atime and __i_mtime and accessing these members should use the new accessor functions. This commit is similar to the OpenAFS commit "Linux 6.6: convert to ctime accessor functions" (072c7934cd1) Add autoconf tests to detect when we need to use the new accessors and introduce new wrapper functions to get and set an inode's atime and mtime. Note, unlike the (072c7934cd1) commit, we need to add support for reading an inode's atime and mtime, so this commit has the getters for the atime and mtime members. Change-Id: Ide818c946ed98a1401ef59864c2cdb4eccee9c99 Reviewed-on: https://gerrit.openafs.org/15597 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Andrew Deason <adeason@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
dir: Introduce struct DirEntryFlex The directory package as implemented in AFS-2 allocates space for each directory entry as a DirEntry struct followed by 0-8 contiguous DirXEntry structs, as needed. This is implemented by: - afs_dir_NameBlobs calculates the number of blocks needed - FindBlobs allocates and returns index of entry - afs_dir_GetBlob returns pointer to 1st DirEntry struct After this, we populate DirEntry (and any contiguous DirXEntry blocks) with open code. Most existing code writes the entry's name via a string copy operation to DirEntry->name, which is only 16 bytes long. Therefore, for dir entry names that are 16 bytes or longer, OpenAFS routinely does string copies that look like buffer overruns. This has not previously caused problems because the OpenAFS code has arranged for a sufficiently large amount of contiguous memory to be available. However, this remains undefined behavior in the C abstract virtual machine; thus compilers are not required to produce safe operation. Recent changes in the OpenAFS build chain have made this approach no longer viable: 1) Linux 6.5 commit df8fc4e934c12b 'kbuild: Enable -fstrict-flex-arrays=3' modified the hardening of several kernel string operations when running with CONFIG_FORTIFY_SOURCE=y. 2) gcc 13 commit 79a89108dd352cd9288f5de35481b1280c7588a5 '__builtin_dynamic_object_size: Recognize builtin' provides some enhancements to _builtin_object_size. The Linux commit above will now use these when the kernel is built with gcc 13. When OpenAFS is built under Linux 6.5 or higher and gcc 13 or higher, the hardened strlcpy will BUG for directory entry names longer than 16 characters. Since there are multiple places where OpenAFS writes directory names, there are several symptoms that may manifest. However, the first one is usually a kernel BUG at cache manager initialization if running with afsd -dynroot _and_ there are any cell names 15 characters or longer in the client CellServDB. (A 15-character cellname reaches the 16 character limit when -dyrnoot adds the RW mountpoint ".<cellname>".) Address this by using flexible arrays (standardized with C99). A flexible array is a variable-length array that is declared with no size at all, e.g., name[]. Create an autoconf test to determine whether the compiler supports flexible arrays. Create a new struct DirEntryFlex. If the compiler supports flexible arrays, define name[]; otherwise retain the name[16] definition. Whenever we write a directory name, use DirEntryFlex so that any hardening will be satisfied that there is sufficient space for the name. However, the actual guarantee that this is true is still provided by the OpenAFS directory routines mentioned above - all of these remain unchanged. The DirEntry struct remains unchanged for continued use in OpenAFS, as well as for any out-of-tree users of the directory package. Change-Id: I6da5c6c295f051be90017084e5b3a3ef24d1271f Reviewed-on: https://gerrit.openafs.org/15573 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Linux: Fix to use time_t instead of time64_t In commit 'Linux 6.6: convert to ctime accessor functions' (072c7934cd) the functiom afs_inode_set_ctime was defined to use time64_t when it should have used a time_t as the data type for the sec parameter. See the commit 'LINUX 5.6: define time_t and use timespec/timespec64' (78049987aa). The time64_t data type was introduced in Linux 3.17. A build failure will occur when building on kernels prior to Linux 3.17. Change-Id: I9b3ce32f8885cde969583cfc74294cdabc54e698 Reviewed-on: https://gerrit.openafs.org/15595 Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
Linux 6.6: Pass request_mask to generic_fillattr The Linux 6.6 commit: "fs: pass the request_mask to generic_fillattr" (0d72b92883) added an additional parameter to Linux's generic_fillattr() function. For openafs, generic_fillattr() is called from the inode_operations method "getattr", which is implemented in afs_linux_getattr(). The value for the request_mask parameter is an existing parameter that is passed to the inode_operations "getattr" method. Add an autoconf test for 4 parameters to the generic_fillattr function and update afs_linux_getattr() to pass the request_mask to generic_fillattr(). Change-Id: Ie1e6b15bd85931debe0fd446760674ddd0492578 Reviewed-on: https://gerrit.openafs.org/15561 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Mark Vitale <mvitale@sinenomine.net> Tested-by: Mark Vitale <mvitale@sinenomine.net> Reviewed-by: Andrew Deason <adeason@sinenomine.net> Reviewed-by: Kailas Zadbuke <kailashsz@in.ibm.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>