Initial commit
This commit is contained in:
332
package/utils/e2fsprogs/Makefile
Normal file
332
package/utils/e2fsprogs/Makefile
Normal file
@@ -0,0 +1,332 @@
|
||||
#
|
||||
# Copyright (C) 2006-2014 OpenWrt.org
|
||||
# Copyright 2010 Vertical Communications
|
||||
# This is free software, licensed under the GNU General Public License v2.
|
||||
# See /LICENSE for more information.
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=e2fsprogs
|
||||
PKG_VERSION:=1.44.5
|
||||
PKG_RELEASE:=2
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
|
||||
PKG_SOURCE_URL:=@KERNEL/linux/kernel/people/tytso/e2fsprogs/v$(PKG_VERSION)/
|
||||
PKG_HASH:=ba5eb3069d69160d96818bb9700de9ab5a8458d9add1fd85d427c0000d34c5b9
|
||||
|
||||
PKG_LICENSE:=GPL-2.0
|
||||
PKG_LICENSE_FILES:=NOTICE
|
||||
PKG_CPE_ID:=cpe:/a:e2fsprogs_project:e2fsprogs
|
||||
|
||||
PKG_BUILD_DEPENDS:=util-linux e2fsprogs/host
|
||||
PKG_INSTALL:=1
|
||||
|
||||
PKG_BUILD_PARALLEL:=1
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
include $(INCLUDE_DIR)/host-build.mk
|
||||
|
||||
define Package/e2fsprogs
|
||||
SECTION:=utils
|
||||
CATEGORY:=Utilities
|
||||
SUBMENU:=Filesystem
|
||||
TITLE:=Ext2/3/4 filesystem utilities
|
||||
URL:=http://e2fsprogs.sourceforge.net/
|
||||
DEPENDS:=+libuuid +libext2fs
|
||||
endef
|
||||
|
||||
define Package/e2fsprogs/description
|
||||
This package contains essential ext2 filesystem utilities which consists of
|
||||
e2fsck, mke2fs and most of the other core ext2 filesystem utilities.
|
||||
endef
|
||||
|
||||
define Package/libext2fs
|
||||
SECTION:=libs
|
||||
CATEGORY:=Libraries
|
||||
TITLE:=ext2/3/4 filesystem library
|
||||
URL:=http://e2fsprogs.sourceforge.net/
|
||||
DEPENDS:=+libuuid +libblkid +libss +libcomerr
|
||||
ABI_VERSION:=2
|
||||
endef
|
||||
|
||||
define Package/libext2fs/description
|
||||
libext2fs is a library which can access ext2, ext3 and ext4 filesystems.
|
||||
endef
|
||||
|
||||
define Package/libss
|
||||
SECTION:=libs
|
||||
CATEGORY:=Libraries
|
||||
TITLE:=command-line interface parsing library
|
||||
URL:=http://e2fsprogs.sourceforge.net/
|
||||
DEPENDS:=+libcomerr
|
||||
ABI_VERSION:=2
|
||||
endef
|
||||
|
||||
define Package/libss/description
|
||||
This pacakge contains libss, a command-line interface parsing library
|
||||
bundled with e2fsprogs.
|
||||
endef
|
||||
|
||||
define Package/libcomerr
|
||||
SECTION:=libs
|
||||
CATEGORY:=Libraries
|
||||
TITLE:=common error description library
|
||||
URL:=http://e2fsprogs.sourceforge.net/
|
||||
DEPENDS:=+libuuid
|
||||
ABI_VERSION:=0
|
||||
endef
|
||||
|
||||
define Package/libcomerr/description
|
||||
This package contains libcom_err, the common error description library
|
||||
bundled with e2fsprogs.
|
||||
endef
|
||||
|
||||
define Package/tune2fs
|
||||
$(call Package/e2fsprogs)
|
||||
TITLE:=Ext2 Filesystem tune utility
|
||||
DEPENDS:= +e2fsprogs
|
||||
endef
|
||||
|
||||
define Package/resize2fs
|
||||
$(call Package/e2fsprogs)
|
||||
TITLE:=Ext2 Filesystem resize utility
|
||||
DEPENDS:= +e2fsprogs
|
||||
endef
|
||||
|
||||
define Package/badblocks
|
||||
$(call Package/e2fsprogs)
|
||||
TITLE:=Ext2 Filesystem badblocks utility
|
||||
DEPENDS:= +e2fsprogs
|
||||
endef
|
||||
|
||||
define Package/dumpe2fs
|
||||
$(call Package/e2fsprogs)
|
||||
TITLE:=Ext2 Filesystem information dumping utility
|
||||
DEPENDS:= +e2fsprogs
|
||||
endef
|
||||
|
||||
define Package/e2freefrag
|
||||
$(call Package/e2fsprogs)
|
||||
TITLE:=Ext2 Filesystem free space fragmentation information utility
|
||||
DEPENDS:= +e2fsprogs
|
||||
endef
|
||||
|
||||
define Package/e4crypt
|
||||
$(call Package/e2fsprogs)
|
||||
TITLE:=Ext4 Filesystem encryption utility
|
||||
DEPENDS:= +e2fsprogs
|
||||
endef
|
||||
|
||||
define Package/filefrag
|
||||
$(call Package/e2fsprogs)
|
||||
TITLE:=Ext2 Filesystem file fragmentation report utility
|
||||
DEPENDS:= +e2fsprogs
|
||||
endef
|
||||
|
||||
define Package/debugfs
|
||||
$(call Package/e2fsprogs)
|
||||
TITLE:=Ext2 Filesystem debugger
|
||||
DEPENDS:= +e2fsprogs
|
||||
endef
|
||||
|
||||
define Package/chattr
|
||||
$(call Package/e2fsprogs)
|
||||
TITLE:=Ext2 Filesystem chattr utility
|
||||
DEPENDS:= +e2fsprogs
|
||||
endef
|
||||
|
||||
define Package/lsattr
|
||||
$(call Package/e2fsprogs)
|
||||
TITLE:=Ext2 Filesystem lsattr utility
|
||||
DEPENDS:= +e2fsprogs
|
||||
endef
|
||||
|
||||
TARGET_CFLAGS += $(FPIC) -ffunction-sections -fdata-sections -flto
|
||||
|
||||
TARGET_LDFLAGS += $(if $(CONFIG_USE_GLIBC),-lrt)
|
||||
TARGET_LDFLAGS += -flto
|
||||
|
||||
CONFIGURE_ARGS += \
|
||||
--disable-testio-debug \
|
||||
--enable-elf-shlibs \
|
||||
--disable-libuuid \
|
||||
--disable-libblkid \
|
||||
--disable-uuidd \
|
||||
--disable-tls \
|
||||
--disable-nls \
|
||||
--disable-rpath \
|
||||
--disable-fuse2fs
|
||||
|
||||
define Build/Prepare
|
||||
$(call Build/Prepare/Default)
|
||||
$(CP) $(SCRIPT_DIR)/config.{guess,sub} $(PKG_BUILD_DIR)/config/
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
+$(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR)/util \
|
||||
BUILDCC="$(HOSTCC)" \
|
||||
CFLAGS="" \
|
||||
CPPFLAGS="" \
|
||||
LDFLAGS="" \
|
||||
V=$(if $(findstring c,$(OPENWRT_VERBOSE)),1,) \
|
||||
subst
|
||||
+$(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) \
|
||||
LDFLAGS=-Wl,--gc-sections \
|
||||
BUILDCC="$(HOSTCC)" \
|
||||
DESTDIR="$(PKG_INSTALL_DIR)" \
|
||||
ELF_OTHER_LIBS="$(TARGET_LDFLAGS) -luuid" \
|
||||
SYSLIBS="$(TARGET_LDFLAGS) -ldl -L$(PKG_BUILD_DIR)/lib/ -l:libcom_err.so.0.0" \
|
||||
V=$(if $(findstring c,$(OPENWRT_VERBOSE)),1,) \
|
||||
all
|
||||
endef
|
||||
|
||||
define Build/InstallDev
|
||||
$(INSTALL_DIR) $(1)/usr/lib/pkgconfig
|
||||
$(CP) $(PKG_BUILD_DIR)/lib/ext2fs/ext2fs.pc $(1)/usr/lib/pkgconfig
|
||||
$(CP) $(PKG_BUILD_DIR)/lib/et/com_err.pc $(1)/usr/lib/pkgconfig
|
||||
|
||||
$(INSTALL_DIR) $(1)/usr/lib
|
||||
$(CP) $(PKG_BUILD_DIR)/lib/libext2fs.{so,a}* $(1)/usr/lib
|
||||
$(CP) $(PKG_BUILD_DIR)/lib/libcom_err.{so,a}* $(1)/usr/lib
|
||||
$(CP) $(PKG_BUILD_DIR)/lib/libss.{so,a}* $(1)/usr/lib
|
||||
|
||||
$(INSTALL_DIR) $(1)/usr/include/ext2fs
|
||||
$(CP) $(PKG_BUILD_DIR)/lib/ext2fs/*.h $(1)/usr/include/ext2fs
|
||||
$(INSTALL_DIR) $(1)/usr/include/et
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/lib/et/*.h $(1)/usr/include/et
|
||||
# Apparently there is some confusion
|
||||
echo "#include <et/com_err.h>" > $(1)/usr/include/com_err.h
|
||||
$(INSTALL_DIR) $(1)/usr/include/ss
|
||||
$(CP) \
|
||||
$(PKG_BUILD_DIR)/lib/ss/ss.h \
|
||||
$(PKG_BUILD_DIR)/lib/ss/ss_err.h \
|
||||
$(1)/usr/include/ss/
|
||||
endef
|
||||
|
||||
define Host/Compile
|
||||
$(MAKE) $(PKG_JOBS) -C $(HOST_BUILD_DIR)/lib/ss mk_cmds
|
||||
$(MAKE) $(PKG_JOBS) -C $(HOST_BUILD_DIR)/lib/et compile_et
|
||||
endef
|
||||
|
||||
define Host/Install
|
||||
$(INSTALL_DIR) $(1)/share/et
|
||||
$(CP) $(HOST_BUILD_DIR)/lib/et/et_[ch].awk $(1)/share/et/
|
||||
$(INSTALL_DIR) $(1)/share/ss
|
||||
$(CP) $(HOST_BUILD_DIR)/lib/ss/ct_c.{sed,awk} $(1)/share/ss/
|
||||
$(INSTALL_DIR) $(1)/bin
|
||||
$(CP) \
|
||||
$(HOST_BUILD_DIR)/lib/et/compile_et \
|
||||
$(HOST_BUILD_DIR)/lib/ss/mk_cmds \
|
||||
$(1)/bin/
|
||||
endef
|
||||
|
||||
define Package/e2fsprogs/conffiles
|
||||
/etc/e2fsck.conf
|
||||
endef
|
||||
|
||||
define Package/e2fsprogs/install
|
||||
$(INSTALL_DIR) $(1)/usr/sbin
|
||||
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/e2fsck $(1)/usr/sbin/
|
||||
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/mke2fs $(1)/usr/sbin/
|
||||
$(LN) mke2fs $(1)/usr/sbin/mkfs.ext2
|
||||
$(LN) mke2fs $(1)/usr/sbin/mkfs.ext3
|
||||
$(LN) mke2fs $(1)/usr/sbin/mkfs.ext4
|
||||
$(LN) e2fsck $(1)/usr/sbin/fsck.ext2
|
||||
$(LN) e2fsck $(1)/usr/sbin/fsck.ext3
|
||||
$(LN) e2fsck $(1)/usr/sbin/fsck.ext4
|
||||
$(INSTALL_DIR) $(1)/usr/lib
|
||||
$(CP) $(PKG_INSTALL_DIR)/usr/lib/libe2p.so.* $(1)/usr/lib/
|
||||
$(INSTALL_DIR) $(1)/etc/init.d
|
||||
$(INSTALL_DIR) $(1)/lib/functions/fsck
|
||||
$(INSTALL_DATA) ./files/e2fsck.sh $(1)/lib/functions/fsck/
|
||||
$(INSTALL_DATA) ./files/e2fsck.conf $(1)/etc/e2fsck.conf
|
||||
endef
|
||||
|
||||
define Package/libcomerr/install
|
||||
$(INSTALL_DIR) $(1)/usr/lib
|
||||
$(CP) $(PKG_INSTALL_DIR)/usr/lib/libcom_err.so.* $(1)/usr/lib/
|
||||
endef
|
||||
|
||||
define Package/libss/install
|
||||
$(INSTALL_DIR) $(1)/usr/lib
|
||||
$(CP) $(PKG_INSTALL_DIR)/usr/lib/libss.so.* $(1)/usr/lib/
|
||||
endef
|
||||
|
||||
define Package/libext2fs/install
|
||||
$(INSTALL_DIR) $(1)/usr/lib
|
||||
$(CP) $(PKG_INSTALL_DIR)/usr/lib/libext2fs.so.* $(1)/usr/lib/
|
||||
endef
|
||||
|
||||
define Package/libext2fs/install_lib
|
||||
$(INSTALL_DIR) $(1)/usr/lib
|
||||
$(CP) $(PKG_BUILD_DIR)/lib/ext2fs/libext2fs.a $(1)/usr/lib/libext2fs_pic.a
|
||||
endef
|
||||
|
||||
define Package/tune2fs/install
|
||||
$(INSTALL_DIR) $(1)/usr/sbin
|
||||
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/tune2fs $(1)/usr/sbin/
|
||||
$(LN) tune2fs $(1)/usr/sbin/findfs
|
||||
endef
|
||||
|
||||
define Package/resize2fs/install
|
||||
$(INSTALL_DIR) $(1)/usr/sbin
|
||||
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/resize2fs $(1)/usr/sbin/
|
||||
endef
|
||||
|
||||
define Package/badblocks/install
|
||||
$(INSTALL_DIR) $(1)/usr/sbin
|
||||
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/badblocks $(1)/usr/sbin/
|
||||
endef
|
||||
|
||||
define Package/dumpe2fs/install
|
||||
$(INSTALL_DIR) $(1)/usr/sbin
|
||||
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/dumpe2fs $(1)/usr/sbin/
|
||||
endef
|
||||
|
||||
define Package/e2freefrag/install
|
||||
$(INSTALL_DIR) $(1)/usr/sbin
|
||||
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/e2freefrag $(1)/usr/sbin/
|
||||
endef
|
||||
|
||||
define Package/e4crypt/install
|
||||
$(INSTALL_DIR) $(1)/usr/sbin
|
||||
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/e4crypt $(1)/usr/sbin/
|
||||
endef
|
||||
|
||||
define Package/filefrag/install
|
||||
$(INSTALL_DIR) $(1)/usr/sbin
|
||||
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/filefrag $(1)/usr/sbin/
|
||||
endef
|
||||
|
||||
define Package/debugfs/install
|
||||
$(INSTALL_DIR) $(1)/usr/sbin
|
||||
$(INSTALL_DIR) $(1)/usr/lib
|
||||
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/debugfs $(1)/usr/sbin/
|
||||
endef
|
||||
|
||||
define Package/chattr/install
|
||||
$(INSTALL_DIR) $(1)/usr/bin
|
||||
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/chattr $(1)/usr/bin/
|
||||
endef
|
||||
|
||||
define Package/lsattr/install
|
||||
$(INSTALL_DIR) $(1)/usr/bin
|
||||
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/lsattr $(1)/usr/bin/
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,e2fsprogs))
|
||||
$(eval $(call BuildPackage,libcomerr))
|
||||
$(eval $(call BuildPackage,libss))
|
||||
$(eval $(call BuildPackage,libext2fs))
|
||||
$(eval $(call BuildPackage,tune2fs))
|
||||
$(eval $(call BuildPackage,resize2fs))
|
||||
$(eval $(call BuildPackage,badblocks))
|
||||
$(eval $(call BuildPackage,dumpe2fs))
|
||||
$(eval $(call BuildPackage,e2freefrag))
|
||||
$(eval $(call BuildPackage,e4crypt))
|
||||
$(eval $(call BuildPackage,filefrag))
|
||||
$(eval $(call BuildPackage,debugfs))
|
||||
$(eval $(call BuildPackage,chattr))
|
||||
$(eval $(call BuildPackage,lsattr))
|
||||
$(eval $(call HostBuild))
|
||||
3
package/utils/e2fsprogs/files/e2fsck.conf
Normal file
3
package/utils/e2fsprogs/files/e2fsck.conf
Normal file
@@ -0,0 +1,3 @@
|
||||
[options]
|
||||
broken_system_clock = true
|
||||
|
||||
38
package/utils/e2fsprogs/files/e2fsck.sh
Normal file
38
package/utils/e2fsprogs/files/e2fsck.sh
Normal file
@@ -0,0 +1,38 @@
|
||||
#!/bin/sh
|
||||
# Copyright 2010 Vertical Communications
|
||||
# Copyright 2012 OpenWrt.org
|
||||
# This is free software, licensed under the GNU General Public License v2.
|
||||
# See /LICENSE for more information.
|
||||
#
|
||||
|
||||
fsck_e2fsck() {
|
||||
set -o pipefail
|
||||
e2fsck -p "$device" 2>&1 | logger -t "fstab: e2fsck ($device)"
|
||||
local status="$?"
|
||||
set +o pipefail
|
||||
case "$status" in
|
||||
0|1) ;; #success
|
||||
2) reboot;;
|
||||
4) echo "e2fsck ($device): Warning! Uncorrected errors."| logger -t fstab
|
||||
return 1
|
||||
;;
|
||||
*) echo "e2fsck ($device): Error $status. Check not complete."| logger -t fstab;;
|
||||
esac
|
||||
return 0
|
||||
}
|
||||
|
||||
fsck_ext2() {
|
||||
fsck_e2fsck "$@"
|
||||
}
|
||||
|
||||
fsck_ext3() {
|
||||
fsck_e2fsck "$@"
|
||||
}
|
||||
|
||||
fsck_ext4() {
|
||||
fsck_e2fsck "$@"
|
||||
}
|
||||
|
||||
append libmount_known_fsck "ext2"
|
||||
append libmount_known_fsck "ext3"
|
||||
append libmount_known_fsck "ext4"
|
||||
40
package/utils/e2fsprogs/patches/000-relocatable.patch
Normal file
40
package/utils/e2fsprogs/patches/000-relocatable.patch
Normal file
@@ -0,0 +1,40 @@
|
||||
--- a/lib/et/compile_et.sh.in
|
||||
+++ b/lib/et/compile_et.sh.in
|
||||
@@ -2,8 +2,14 @@
|
||||
#
|
||||
#
|
||||
|
||||
-AWK=@AWK@
|
||||
-DIR=@datadir@/et
|
||||
+if test "x$STAGING_DIR" = x ; then
|
||||
+ AWK=@AWK@
|
||||
+ DIR=@datadir@/et
|
||||
+else
|
||||
+ AWK=awk
|
||||
+ DIR="$STAGING_DIR/../hostpkg/share/et"
|
||||
+fi
|
||||
+
|
||||
|
||||
if test "$1" = "--build-tree" ; then
|
||||
shift;
|
||||
--- a/lib/ss/mk_cmds.sh.in
|
||||
+++ b/lib/ss/mk_cmds.sh.in
|
||||
@@ -2,10 +2,16 @@
|
||||
#
|
||||
#
|
||||
|
||||
-DIR=@datadir@/ss
|
||||
-AWK=@AWK@
|
||||
SED=sed
|
||||
|
||||
+if test "x$STAGING_DIR" = x ; then
|
||||
+ DIR=@datadir@/ss
|
||||
+ AWK=@AWK@
|
||||
+else
|
||||
+ DIR="$STAGING_DIR/../hostpkg/share/ss"
|
||||
+ AWK=awk
|
||||
+fi
|
||||
+
|
||||
for as_var in \
|
||||
LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \
|
||||
LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \
|
||||
13
package/utils/e2fsprogs/patches/001-com_err_version.patch
Normal file
13
package/utils/e2fsprogs/patches/001-com_err_version.patch
Normal file
@@ -0,0 +1,13 @@
|
||||
--- a/lib/et/Makefile.in
|
||||
+++ b/lib/et/Makefile.in
|
||||
@@ -25,8 +25,8 @@ SHARE_FILES= et_c.awk et_h.awk
|
||||
LIBRARY= libcom_err
|
||||
LIBDIR= et
|
||||
|
||||
-ELF_VERSION = 2.1
|
||||
-ELF_SO_VERSION = 2
|
||||
+ELF_VERSION = 0.0
|
||||
+ELF_SO_VERSION = 0
|
||||
ELF_IMAGE = libcom_err
|
||||
ELF_MYDIR = et
|
||||
ELF_INSTALL_DIR = $(root_libdir)
|
||||
@@ -0,0 +1,10 @@
|
||||
--- a/util/subst.c
|
||||
+++ b/util/subst.c
|
||||
@@ -10,6 +10,7 @@
|
||||
#else
|
||||
#define HAVE_SYS_STAT_H
|
||||
#define HAVE_SYS_TIME_H
|
||||
+#define HAVE_SYS_STAT_H
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
@@ -0,0 +1,203 @@
|
||||
From 09fe1fd2a1f9efc3091b4fc61f1876d0785956a8 Mon Sep 17 00:00:00 2001
|
||||
From: Theodore Ts'o <tytso@mit.edu>
|
||||
Date: Sun, 1 Sep 2019 00:59:16 -0400
|
||||
Subject: libsupport: add checks to prevent buffer overrun bugs in quota code
|
||||
|
||||
A maliciously corrupted file systems can trigger buffer overruns in
|
||||
the quota code used by e2fsck. To fix this, add sanity checks to the
|
||||
quota header fields as well as to block number references in the quota
|
||||
tree.
|
||||
|
||||
Addresses: CVE-2019-5094
|
||||
Addresses: TALOS-2019-0887
|
||||
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
|
||||
(cherry picked from commit 8dbe7b475ec5e91ed767239f0e85880f416fc384)
|
||||
---
|
||||
lib/support/mkquota.c | 1 +
|
||||
lib/support/quotaio_tree.c | 71 ++++++++++++++++++++++++++++++----------------
|
||||
lib/support/quotaio_v2.c | 28 ++++++++++++++++++
|
||||
3 files changed, 76 insertions(+), 24 deletions(-)
|
||||
|
||||
--- a/lib/support/mkquota.c
|
||||
+++ b/lib/support/mkquota.c
|
||||
@@ -671,6 +671,7 @@ errcode_t quota_compare_and_update(quota
|
||||
err = qh.qh_ops->scan_dquots(&qh, scan_dquots_callback, &scan_data);
|
||||
if (err) {
|
||||
log_debug("Error scanning dquots");
|
||||
+ *usage_inconsistent = 1;
|
||||
goto out_close_qh;
|
||||
}
|
||||
|
||||
--- a/lib/support/quotaio_tree.c
|
||||
+++ b/lib/support/quotaio_tree.c
|
||||
@@ -540,6 +540,17 @@ struct dquot *qtree_read_dquot(struct qu
|
||||
return dquot;
|
||||
}
|
||||
|
||||
+static int check_reference(struct quota_handle *h, unsigned int blk)
|
||||
+{
|
||||
+ if (blk >= h->qh_info.u.v2_mdqi.dqi_qtree.dqi_blocks) {
|
||||
+ log_err("Illegal reference (%u >= %u) in %s quota file",
|
||||
+ blk, h->qh_info.u.v2_mdqi.dqi_qtree.dqi_blocks,
|
||||
+ quota_type2name(h->qh_type));
|
||||
+ return -1;
|
||||
+ }
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
/*
|
||||
* Scan all dquots in file and call callback on each
|
||||
*/
|
||||
@@ -558,7 +569,7 @@ static int report_block(struct dquot *dq
|
||||
int entries, i;
|
||||
|
||||
if (!buf)
|
||||
- return 0;
|
||||
+ return -1;
|
||||
|
||||
set_bit(bitmap, blk);
|
||||
read_blk(dquot->dq_h, blk, buf);
|
||||
@@ -580,23 +591,12 @@ static int report_block(struct dquot *dq
|
||||
return entries;
|
||||
}
|
||||
|
||||
-static void check_reference(struct quota_handle *h, unsigned int blk)
|
||||
-{
|
||||
- if (blk >= h->qh_info.u.v2_mdqi.dqi_qtree.dqi_blocks)
|
||||
- log_err("Illegal reference (%u >= %u) in %s quota file. "
|
||||
- "Quota file is probably corrupted.\n"
|
||||
- "Please run e2fsck (8) to fix it.",
|
||||
- blk,
|
||||
- h->qh_info.u.v2_mdqi.dqi_qtree.dqi_blocks,
|
||||
- quota_type2name(h->qh_type));
|
||||
-}
|
||||
-
|
||||
static int report_tree(struct dquot *dquot, unsigned int blk, int depth,
|
||||
char *bitmap,
|
||||
int (*process_dquot) (struct dquot *, void *),
|
||||
void *data)
|
||||
{
|
||||
- int entries = 0, i;
|
||||
+ int entries = 0, ret, i;
|
||||
dqbuf_t buf = getdqbuf();
|
||||
__le32 *ref = (__le32 *) buf;
|
||||
|
||||
@@ -607,22 +607,40 @@ static int report_tree(struct dquot *dqu
|
||||
if (depth == QT_TREEDEPTH - 1) {
|
||||
for (i = 0; i < QT_BLKSIZE >> 2; i++) {
|
||||
blk = ext2fs_le32_to_cpu(ref[i]);
|
||||
- check_reference(dquot->dq_h, blk);
|
||||
- if (blk && !get_bit(bitmap, blk))
|
||||
- entries += report_block(dquot, blk, bitmap,
|
||||
- process_dquot, data);
|
||||
+ if (check_reference(dquot->dq_h, blk)) {
|
||||
+ entries = -1;
|
||||
+ goto errout;
|
||||
+ }
|
||||
+ if (blk && !get_bit(bitmap, blk)) {
|
||||
+ ret = report_block(dquot, blk, bitmap,
|
||||
+ process_dquot, data);
|
||||
+ if (ret < 0) {
|
||||
+ entries = ret;
|
||||
+ goto errout;
|
||||
+ }
|
||||
+ entries += ret;
|
||||
+ }
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < QT_BLKSIZE >> 2; i++) {
|
||||
blk = ext2fs_le32_to_cpu(ref[i]);
|
||||
if (blk) {
|
||||
- check_reference(dquot->dq_h, blk);
|
||||
- entries += report_tree(dquot, blk, depth + 1,
|
||||
- bitmap, process_dquot,
|
||||
- data);
|
||||
+ if (check_reference(dquot->dq_h, blk)) {
|
||||
+ entries = -1;
|
||||
+ goto errout;
|
||||
+ }
|
||||
+ ret = report_tree(dquot, blk, depth + 1,
|
||||
+ bitmap, process_dquot,
|
||||
+ data);
|
||||
+ if (ret < 0) {
|
||||
+ entries = ret;
|
||||
+ goto errout;
|
||||
+ }
|
||||
+ entries += ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
+errout:
|
||||
freedqbuf(buf);
|
||||
return entries;
|
||||
}
|
||||
@@ -642,6 +660,7 @@ int qtree_scan_dquots(struct quota_handl
|
||||
int (*process_dquot) (struct dquot *, void *),
|
||||
void *data)
|
||||
{
|
||||
+ int ret;
|
||||
char *bitmap;
|
||||
struct v2_mem_dqinfo *v2info = &h->qh_info.u.v2_mdqi;
|
||||
struct qtree_mem_dqinfo *info = &v2info->dqi_qtree;
|
||||
@@ -655,10 +674,14 @@ int qtree_scan_dquots(struct quota_handl
|
||||
ext2fs_free_mem(&dquot);
|
||||
return -1;
|
||||
}
|
||||
- v2info->dqi_used_entries = report_tree(dquot, QT_TREEOFF, 0, bitmap,
|
||||
- process_dquot, data);
|
||||
+ ret = report_tree(dquot, QT_TREEOFF, 0, bitmap, process_dquot, data);
|
||||
+ if (ret < 0)
|
||||
+ goto errout;
|
||||
+ v2info->dqi_used_entries = ret;
|
||||
v2info->dqi_data_blocks = find_set_bits(bitmap, info->dqi_blocks);
|
||||
+ ret = 0;
|
||||
+errout:
|
||||
ext2fs_free_mem(&bitmap);
|
||||
ext2fs_free_mem(&dquot);
|
||||
- return 0;
|
||||
+ return ret;
|
||||
}
|
||||
--- a/lib/support/quotaio_v2.c
|
||||
+++ b/lib/support/quotaio_v2.c
|
||||
@@ -175,6 +175,8 @@ static int v2_check_file(struct quota_ha
|
||||
static int v2_init_io(struct quota_handle *h)
|
||||
{
|
||||
struct v2_disk_dqinfo ddqinfo;
|
||||
+ struct v2_mem_dqinfo *info;
|
||||
+ __u64 filesize;
|
||||
|
||||
h->qh_info.u.v2_mdqi.dqi_qtree.dqi_entry_size =
|
||||
sizeof(struct v2r1_disk_dqblk);
|
||||
@@ -185,6 +187,32 @@ static int v2_init_io(struct quota_handl
|
||||
sizeof(ddqinfo)) != sizeof(ddqinfo))
|
||||
return -1;
|
||||
v2_disk2memdqinfo(&h->qh_info, &ddqinfo);
|
||||
+
|
||||
+ /* Check to make sure quota file info is sane */
|
||||
+ info = &h->qh_info.u.v2_mdqi;
|
||||
+ if (ext2fs_file_get_lsize(h->qh_qf.e2_file, &filesize))
|
||||
+ return -1;
|
||||
+ if ((filesize > (1U << 31)) ||
|
||||
+ (info->dqi_qtree.dqi_blocks >
|
||||
+ (filesize + QT_BLKSIZE - 1) >> QT_BLKSIZE_BITS)) {
|
||||
+ log_err("Quota inode %u corrupted: file size %llu; "
|
||||
+ "dqi_blocks %u", h->qh_qf.ino,
|
||||
+ filesize, info->dqi_qtree.dqi_blocks);
|
||||
+ return -1;
|
||||
+ }
|
||||
+ if (info->dqi_qtree.dqi_free_blk >= info->dqi_qtree.dqi_blocks) {
|
||||
+ log_err("Quota inode %u corrupted: free_blk %u; dqi_blocks %u",
|
||||
+ h->qh_qf.ino, info->dqi_qtree.dqi_free_blk,
|
||||
+ info->dqi_qtree.dqi_blocks);
|
||||
+ return -1;
|
||||
+ }
|
||||
+ if (info->dqi_qtree.dqi_free_entry >= info->dqi_qtree.dqi_blocks) {
|
||||
+ log_err("Quota inode %u corrupted: free_entry %u; "
|
||||
+ "dqi_blocks %u", h->qh_qf.ino,
|
||||
+ info->dqi_qtree.dqi_free_entry,
|
||||
+ info->dqi_qtree.dqi_blocks);
|
||||
+ return -1;
|
||||
+ }
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user