~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/xfs/scrub/symlink.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /*
  3  * Copyright (C) 2017-2023 Oracle.  All Rights Reserved.
  4  * Author: Darrick J. Wong <djwong@kernel.org>
  5  */
  6 #include "xfs.h"
  7 #include "xfs_fs.h"
  8 #include "xfs_shared.h"
  9 #include "xfs_format.h"
 10 #include "xfs_trans_resv.h"
 11 #include "xfs_mount.h"
 12 #include "xfs_log_format.h"
 13 #include "xfs_trans.h"
 14 #include "xfs_inode.h"
 15 #include "xfs_symlink.h"
 16 #include "xfs_health.h"
 17 #include "xfs_symlink_remote.h"
 18 #include "scrub/scrub.h"
 19 #include "scrub/common.h"
 20 #include "scrub/health.h"
 21 #include "scrub/repair.h"
 22 
 23 /* Set us up to scrub a symbolic link. */
 24 int
 25 xchk_setup_symlink(
 26         struct xfs_scrub        *sc)
 27 {
 28         unsigned int            resblks = 0;
 29         int                     error;
 30 
 31         /* Allocate the buffer without the inode lock held. */
 32         sc->buf = kvzalloc(XFS_SYMLINK_MAXLEN + 1, XCHK_GFP_FLAGS);
 33         if (!sc->buf)
 34                 return -ENOMEM;
 35 
 36         if (xchk_could_repair(sc)) {
 37                 error = xrep_setup_symlink(sc, &resblks);
 38                 if (error)
 39                         return error;
 40         }
 41 
 42         return xchk_setup_inode_contents(sc, resblks);
 43 }
 44 
 45 /* Symbolic links. */
 46 
 47 int
 48 xchk_symlink(
 49         struct xfs_scrub        *sc)
 50 {
 51         struct xfs_inode        *ip = sc->ip;
 52         struct xfs_ifork        *ifp;
 53         loff_t                  len;
 54         int                     error = 0;
 55 
 56         if (!S_ISLNK(VFS_I(ip)->i_mode))
 57                 return -ENOENT;
 58 
 59         if (xchk_file_looks_zapped(sc, XFS_SICK_INO_SYMLINK_ZAPPED)) {
 60                 xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, 0);
 61                 return 0;
 62         }
 63 
 64         ifp = xfs_ifork_ptr(ip, XFS_DATA_FORK);
 65         len = ip->i_disk_size;
 66 
 67         /* Plausible size? */
 68         if (len > XFS_SYMLINK_MAXLEN || len <= 0) {
 69                 xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, 0);
 70                 return 0;
 71         }
 72 
 73         /* Inline symlink? */
 74         if (ifp->if_format == XFS_DINODE_FMT_LOCAL) {
 75                 if (len > xfs_inode_data_fork_size(ip) ||
 76                     len > strnlen(ifp->if_data, xfs_inode_data_fork_size(ip)))
 77                         xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, 0);
 78                 return 0;
 79         }
 80 
 81         /* Remote symlink; must read the contents. */
 82         error = xfs_symlink_remote_read(sc->ip, sc->buf);
 83         if (!xchk_fblock_process_error(sc, XFS_DATA_FORK, 0, &error))
 84                 return error;
 85         if (strnlen(sc->buf, XFS_SYMLINK_MAXLEN) < len)
 86                 xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, 0);
 87 
 88         /* If a remote symlink is clean, it is clearly not zapped. */
 89         xchk_mark_healthy_if_clean(sc, XFS_SICK_INO_SYMLINK_ZAPPED);
 90         return 0;
 91 }
 92 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php