Skip to content

Commit

Permalink
Rebuild some binaries with musl-libc to avoid virus false positive (i…
Browse files Browse the repository at this point in the history
…ssue ventoy#660)
  • Loading branch information
ventoy committed Dec 22, 2020
1 parent ff0ad76 commit 4707b76
Show file tree
Hide file tree
Showing 26 changed files with 210 additions and 47 deletions.
38 changes: 27 additions & 11 deletions BUSYBOX/build.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
======== Build busybox 1.32 for aarch64 ========

ARCH=arm64 CROSS_COMPILE=aarch64-linux- make defconfig
ARCH=arm64 CROSS_COMPILE=aarch64-linux- make menuconfig
----> enable static build
----> enable ar
----> enable inotifyd


======== How to build ash/hexdump/xzcat for aarch64 ========
#How to get ash.config/hexdump.cofig/xzcat.config
#ARCH=arm64 CROSS_COMPILE=aarch64-linux- make allnoconfig
#ARCH=arm64 CROSS_COMPILE=aarch64-linux- make menuconfig
#----> enable static build
#----> enable xzcat
#get aarch64_xzcat.config

tar xf busybox-1.32.0.tar.bz2
cd busybox-1.32.0
copy aarch64_xzcat.config as .config
ARCH=arm64 CROSS_COMPILE=aarch64-linux- make
rename ./busybox to xzcat



======== How to build ash/hexdump/xzcat for x86_64 ==========
#How to get ash.config/hexdump.cofig/xzcat.config
#make allnoconfig
#make menuconfig
#----> enable static build
#----> enable xzcat
#get x86_64_xzcat.config

ARCH=arm64 CROSS_COMPILE=aarch64-linux- make allnoconfig

tar xf busybox-1.32.0.tar.bz2
cd busybox-1.32.0
copy x86_64_xzcat.config as .config
modify Makefile
CC = gcc -specs "/usr/local/musl/lib/musl-gcc.specs"
MODFLAGS = -DMODULE -specs "/usr/local/musl/lib/musl-gcc.specs"
make
rename ./busybox to xzcat

======== use mini-native-x86_64 uclibc to build ash/hexdump/busybox for x86_64 ==========


6 changes: 5 additions & 1 deletion BUSYBOX/chmod/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@

DSTDIR=../../IMG/cpio/ventoy/busybox

rm -f vtchmod32 vtchmod64 vtchmodaa64
rm -f vtchmod32 vtchmod64 vtchmod64_musl vtchmodaa64
rm -f $DSTDIR/vtchmod32 $DSTDIR/vtchmod64 $DSTDIR/vtchmodaa64

/opt/diet32/bin/diet gcc -Os -m32 vtchmod.c -o vtchmod32
/opt/diet64/bin/diet gcc -Os vtchmod.c -o vtchmod64
aarch64-linux-gcc -Os -static vtchmod.c -o vtchmodaa64
aarch64-linux-strip --strip-all vtchmodaa64

gcc -specs "/usr/local/musl/lib/musl-gcc.specs" -Os -static vtchmod.c -o vtchmod64_musl
strip --strip-all vtchmod64_musl

chmod 777 vtchmod32
chmod 777 vtchmod64
chmod 777 vtchmodaa64
chmod 777 vtchmod64_musl

cp -a vtchmod32 $DSTDIR/
cp -a vtchmod64 $DSTDIR/
cp -a vtchmodaa64 $DSTDIR/
cp -a vtchmod64_musl $DSTDIR/

Binary file added BUSYBOX/chmod/vtchmod64_musl
Binary file not shown.
12 changes: 4 additions & 8 deletions DMSETUP/build.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,16 @@ build for 32bit, static linked with dietlibc


======================== Build for 64bit dmsetup =========================
https://www.uclibc.org/downloads/binaries/0.9.30.1/mini-native-x86_64.tar.bz2
1. extract device mapper source code
2. extract mini-native-x86_64.tar.bz2
3. chroot to mini-native-x86_64
3. ./configure --disable-nls --disable-selinux --disable-shared --enable-static_link
2. ./configure --disable-nls --disable-selinux --disable-shared --enable-static_link CC='gcc -specs /usr/local/musl/lib/musl-gcc.specs'
3. touch include/linux/limits.h include/linux/types.h
echo '#include <sys/mount.h>' > include/linux/fs.h
4. make
5. strip dmsetup/dmsetup.static
5. strip --strip-all dmsetup/dmsetup.static
6. get dmsetup/dmsetup.static as the dmsetup64 binary file




======================== Build for arm64 dmsetup =========================
https://www.uclibc.org/downloads/binaries/0.9.30.1/mini-native-x86_64.tar.bz2
1. extract device mapper source code
2. ./configure CC=aarch64-linux-gcc --target=arm --host=x86_64-linux-gnu --disable-nls --disable-selinux --disable-shared --enable-static_link
3. modify include/configure.h file
Expand Down
Binary file modified DMSETUP/dmsetup64
Binary file not shown.
14 changes: 14 additions & 0 deletions DOC/BuildVentoyFromSource.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,27 @@
2.2 Download third-part source code

https://www.fefe.de/dietlibc/dietlibc-0.34.tar.xz ===> /home/Ventoy-master/DOC/dietlibc-0.34.tar.xz
https://musl.libc.org/releases/musl-1.2.1.tar.gz ===> /home/Ventoy-master/DOC/musl-1.2.1.tar.gz
https://ftp.gnu.org/gnu/grub/grub-2.04.tar.xz ===> /home/Ventoy-master/GRUB2/grub-2.04.tar.xz
https://codeload.github.com/tianocore/edk2/zip/edk2-stable201911 ===> /home/Ventoy-master/EDK2/edk2-edk2-stable201911.zip
https://codeload.github.com/relan/exfat/zip/v1.3.0 ===> /home/Ventoy-master/ExFAT/exfat-1.3.0.zip
https://codeload.github.com/libfuse/libfuse/zip/fuse-2.9.9 ===> /home/Ventoy-master/ExFAT/libfuse-fuse-2.9.9.zip
https://releases.linaro.org/components/toolchain/binaries/7.4-2019.02/aarch64-linux-gnu/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz ===> /opt/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz
https://toolchains.bootlin.com/downloads/releases/toolchains/aarch64/tarballs/aarch64--uclibc--stable-2020.08-1.tar.bz2 ===> /opt/aarch64--uclibc--stable-2020.08-1.tar.bz2

2.3 Prepare third-part tools
cd /home/Ventoy-master/DOC/
tar xf musl-1.2.1.tar.gz
cd musl-1.2.1
./configure && make install

tar xf /opt/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz -C /opt
tar xf /opt/aarch64--uclibc--stable-2020.08-1.tar.bz2 -C /opt

2.4 Set PATH envrioment
export PATH=$PATH:/opt/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin:/opt/aarch64--uclibc--stable-2020.08-1/bin
better to add this line to /root/.bashrc and relogin as root


==========================================
3. All in one script
Expand Down
87 changes: 62 additions & 25 deletions GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1709,6 +1709,7 @@ int ventoy_check_device_result(int ret)

int ventoy_check_device(grub_device_t dev)
{
int workaround = 0;
grub_file_t file;
grub_uint64_t offset;
char devname[64];
Expand All @@ -1726,11 +1727,29 @@ int ventoy_check_device(grub_device_t dev)
0 == ventoy_check_file_exist("(%s,2)/grub/localboot.cfg", dev->disk->name) ||
0 == ventoy_check_file_exist("(%s,2)/tool/mount.exfat-fuse_aarch64", dev->disk->name))
{
return ventoy_check_device_result(2 | 0x1000);
#ifndef GRUB_MACHINE_EFI
if (0 == ventoy_check_file_exist("(ventoydisk)/ventoy/ventoy.cpio", dev->disk->name) ||
0 == ventoy_check_file_exist("(ventoydisk)/grub/localboot.cfg", dev->disk->name) ||
0 == ventoy_check_file_exist("(ventoydisk)/tool/mount.exfat-fuse_aarch64", dev->disk->name))
{
return ventoy_check_device_result(2 | 0x1000);
}
else
{
workaround = 1;
}
#endif
}

/* We must have partition 2 */
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "(%s,2)/ventoy/ventoy.cpio", dev->disk->name);
if (workaround)
{
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s", "(ventoydisk)/ventoy/ventoy.cpio");
}
else
{
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "(%s,2)/ventoy/ventoy.cpio", dev->disk->name);
}
if (!file)
{
return ventoy_check_device_result(3 | 0x1000);
Expand All @@ -1748,37 +1767,55 @@ int ventoy_check_device(grub_device_t dev)
return ventoy_check_device_result(5);
}

offset = partition->start + partition->len;
partition = file->device->disk->partition;
if ((partition->number != 1) || (partition->len != 65536) || (offset != partition->start))
if (workaround)
{
grub_file_close(file);
return ventoy_check_device_result(6);
ventoy_part_table *PartTbl = g_ventoy_part_info->MBR.PartTbl;
if (PartTbl[1].StartSectorId != PartTbl[0].StartSectorId + PartTbl[0].SectorCount ||
PartTbl[1].SectorCount != 65536)
{
grub_file_close(file);
return ventoy_check_device_result(6);
}
}
grub_file_close(file);

grub_snprintf(devname, sizeof(devname), "%s,2", dev->disk->name);
dev2 = grub_device_open(devname);
if (!dev2)
else
{
return ventoy_check_device_result(7);
offset = partition->start + partition->len;
partition = file->device->disk->partition;
if ((partition->number != 1) || (partition->len != 65536) || (offset != partition->start))
{
grub_file_close(file);
return ventoy_check_device_result(7);
}
}

fs = grub_fs_probe(dev2);
if (!fs)
{
grub_device_close(dev2);
return ventoy_check_device_result(8);
}
grub_file_close(file);

fs->fs_label(dev2, &label);
if ((!label) || grub_strncmp("VTOYEFI", label, 7))
if (workaround == 0)
{
grub_device_close(dev2);
return ventoy_check_device_result(9);
}
grub_snprintf(devname, sizeof(devname), "%s,2", dev->disk->name);
dev2 = grub_device_open(devname);
if (!dev2)
{
return ventoy_check_device_result(8);
}

grub_device_close(dev2);
fs = grub_fs_probe(dev2);
if (!fs)
{
grub_device_close(dev2);
return ventoy_check_device_result(9);
}

fs->fs_label(dev2, &label);
if ((!label) || grub_strncmp("VTOYEFI", label, 7))
{
grub_device_close(dev2);
return ventoy_check_device_result(10);
}

grub_device_close(dev2);
}

return ventoy_check_device_result(0);
}

Expand Down
4 changes: 2 additions & 2 deletions IMG/cpio/sbin/init
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ if [ -e $BUSYBOX_PATH/32h ]; then
if [ -s $BUSYBOX_PATH/busybox ]; then
$BUSYBOX_PATH/vtchmod64 $BUSYBOX_PATH/busybox
else
$BUSYBOX_PATH/xzminidec64_uclibc < $BUSYBOX_PATH/busybox64.xz > $BUSYBOX_PATH/busybox
$BUSYBOX_PATH/vtchmod64_uclibc $BUSYBOX_PATH/busybox
$BUSYBOX_PATH/xzminidec64_musl < $BUSYBOX_PATH/busybox64.xz > $BUSYBOX_PATH/busybox
$BUSYBOX_PATH/vtchmod64_musl $BUSYBOX_PATH/busybox
fi
fi
else
Expand Down
Binary file modified IMG/cpio/ventoy/busybox/64h
Binary file not shown.
Binary file added IMG/cpio/ventoy/busybox/vtchmod64_musl
Binary file not shown.
Binary file removed IMG/cpio/ventoy/busybox/vtchmod64_uclibc
Binary file not shown.
Binary file added IMG/cpio/ventoy/busybox/xzminidec64_musl
Binary file not shown.
Binary file removed IMG/cpio/ventoy/busybox/xzminidec64_uclibc
Binary file not shown.
Binary file modified INSTALL/EFI/BOOT/BOOTAA64.EFI
Binary file not shown.
Binary file modified INSTALL/EFI/BOOT/grubia32_real.efi
Binary file not shown.
Binary file modified INSTALL/EFI/BOOT/grubx64_real.efi
Binary file not shown.
Binary file modified INSTALL/grub/i386-pc/core.img
Binary file not shown.
Binary file modified INSTALL/tool/x86_64/ash
Binary file not shown.
Binary file modified INSTALL/tool/x86_64/hexdump
Binary file not shown.
Binary file modified INSTALL/tool/x86_64/xzcat
Binary file not shown.
Binary file modified INSTALL/ventoy/ventoy.cpio
Binary file not shown.
Binary file modified INSTALL/ventoy/vtloopex.cpio
Binary file not shown.
Binary file modified LANGUAGES/languages.ini
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#
# Makefile
#
# Author: Lasse Collin <lasse.collin@tukaani.org>
#
# This file has been put into the public domain.
# You can do whatever you want with this file.
#

CC = gcc -specs "/usr/local/musl/lib/musl-gcc.specs" -Os -static -std=gnu89
BCJ_CPPFLAGS = -DXZ_DEC_X86 -DXZ_DEC_POWERPC -DXZ_DEC_IA64 \
-DXZ_DEC_ARM -DXZ_DEC_ARMTHUMB -DXZ_DEC_SPARC
CPPFLAGS = -DXZ_USE_CRC64 -DXZ_DEC_ANY_CHECK
CFLAGS = -ggdb3 -O2 -pedantic -Wall -Wextra
RM = rm -f
VPATH = ../linux/include/linux ../linux/lib/xz
COMMON_SRCS = xz_crc32.c xz_crc64.c xz_dec_stream.c xz_dec_lzma2.c xz_dec_bcj.c
COMMON_OBJS = $(COMMON_SRCS:.c=.o)
XZMINIDEC_OBJS = xzminidec.o
BYTETEST_OBJS = bytetest.o
BUFTEST_OBJS = buftest.o
BOOTTEST_OBJS = boottest.o
XZ_HEADERS = xz.h xz_private.h xz_stream.h xz_lzma2.h xz_config.h
PROGRAMS = xzminidec bytetest buftest boottest

ALL_CPPFLAGS = -I../linux/include/linux -I. $(BCJ_CPPFLAGS) $(CPPFLAGS)

all: $(PROGRAMS)

%.o: %.c $(XZ_HEADERS)
$(CC) $(ALL_CPPFLAGS) $(CFLAGS) -c -o $@ $<

xzminidec: $(COMMON_OBJS) $(XZMINIDEC_OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(COMMON_OBJS) $(XZMINIDEC_OBJS)

bytetest: $(COMMON_OBJS) $(BYTETEST_OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(COMMON_OBJS) $(BYTETEST_OBJS)

buftest: $(COMMON_OBJS) $(BUFTEST_OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(COMMON_OBJS) $(BUFTEST_OBJS)

boottest: $(BOOTTEST_OBJS) $(COMMON_SRCS)
$(CC) $(ALL_CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $(BOOTTEST_OBJS)

.PHONY: clean
clean:
-$(RM) $(COMMON_OBJS) $(XZMINIDEC_OBJS) $(BUFTEST_OBJS) \
$(BOOTTEST_OBJS) $(PROGRAMS)
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#
# Makefile
#
# Author: Lasse Collin <lasse.collin@tukaani.org>
#
# This file has been put into the public domain.
# You can do whatever you want with this file.
#

CC = /opt/aarch64--uclibc--stable-2020.08-1/bin/aarch64-linux-gcc -Os -static -std=gnu89
BCJ_CPPFLAGS = -DXZ_DEC_X86 -DXZ_DEC_POWERPC -DXZ_DEC_IA64 \
-DXZ_DEC_ARM -DXZ_DEC_ARMTHUMB -DXZ_DEC_SPARC
CPPFLAGS = -DXZ_USE_CRC64 -DXZ_DEC_ANY_CHECK
CFLAGS = -ggdb3 -O2 -pedantic -Wall -Wextra
RM = rm -f
VPATH = ../linux/include/linux ../linux/lib/xz
COMMON_SRCS = xz_crc32.c xz_crc64.c xz_dec_stream.c xz_dec_lzma2.c xz_dec_bcj.c
COMMON_OBJS = $(COMMON_SRCS:.c=.o)
XZMINIDEC_OBJS = xzminidec.o
BYTETEST_OBJS = bytetest.o
BUFTEST_OBJS = buftest.o
BOOTTEST_OBJS = boottest.o
XZ_HEADERS = xz.h xz_private.h xz_stream.h xz_lzma2.h xz_config.h
PROGRAMS = xzminidec bytetest buftest boottest

ALL_CPPFLAGS = -I../linux/include/linux -I. $(BCJ_CPPFLAGS) $(CPPFLAGS)

all: $(PROGRAMS)

%.o: %.c $(XZ_HEADERS)
$(CC) $(ALL_CPPFLAGS) $(CFLAGS) -c -o $@ $<

xzminidec: $(COMMON_OBJS) $(XZMINIDEC_OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(COMMON_OBJS) $(XZMINIDEC_OBJS)

bytetest: $(COMMON_OBJS) $(BYTETEST_OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(COMMON_OBJS) $(BYTETEST_OBJS)

buftest: $(COMMON_OBJS) $(BUFTEST_OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(COMMON_OBJS) $(BUFTEST_OBJS)

boottest: $(BOOTTEST_OBJS) $(COMMON_SRCS)
$(CC) $(ALL_CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $(BOOTTEST_OBJS)

.PHONY: clean
clean:
-$(RM) $(COMMON_OBJS) $(XZMINIDEC_OBJS) $(BUFTEST_OBJS) \
$(BOOTTEST_OBJS) $(PROGRAMS)
Binary file removed VtoyTool/vtoytool/01/vtoytool_64
Binary file not shown.

0 comments on commit 4707b76

Please sign in to comment.