From d4459cf9f36e348276f6739acda256171ff6ffbd Mon Sep 17 00:00:00 2001 From: Masamichi Takagi Date: Wed, 24 Jan 2018 00:16:12 +0900 Subject: [PATCH] Add check to confirm IHK and McKernel with the same version are used --- arch/x86_64/tools/mcreboot-smp-x86.sh.in | 8 ++++++++ config.h.in | 10 +++++++--- configure | 17 +++++++++++++++++ configure.ac | 9 +++++++++ executer/user/Makefile.in | 4 ++-- executer/user/mcexec.c | 15 +++++++++++++++ 6 files changed, 58 insertions(+), 5 deletions(-) diff --git a/arch/x86_64/tools/mcreboot-smp-x86.sh.in b/arch/x86_64/tools/mcreboot-smp-x86.sh.in index 0f63c403..0e87e049 100644 --- a/arch/x86_64/tools/mcreboot-smp-x86.sh.in +++ b/arch/x86_64/tools/mcreboot-smp-x86.sh.in @@ -19,6 +19,7 @@ ETCDIR=@ETCDIR@ KMODDIR="${prefix}/kmod" KERNDIR="${prefix}/@TARGET@/kernel" ENABLE_MCOVERLAYFS="@ENABLE_MCOVERLAYFS@" +MCK_BUILDID=@BUILDID@ mem="512M@0" cpus="" @@ -361,6 +362,13 @@ if ! grep mcctrl /proc/modules &>/dev/null; then fi fi +# Check that different versions of binaries/scripts are not mixed +IHK_BUILDID=`${SBINDIR}/ihkconfig 0 get buildid` +if [ "${IHK_BUILDID}" != "${MCK_BUILDID}" ]; then + echo "IHK build-id (${IHK_BUILDID}) didn't match McKernel build-id (${MCK_BUILDID})." >&2 + exit 1 +fi + # Destroy all LWK instances if ls /dev/mcos* 1>/dev/null 2>&1; then for i in /dev/mcos*; do diff --git a/config.h.in b/config.h.in index 1c6bbdf1..2040c8cb 100644 --- a/config.h.in +++ b/config.h.in @@ -3,21 +3,25 @@ /* Path of install directory for binary */ #undef BINDIR +/* Id of IHK.ko maching of which is checked at run-time by reboot script and + mcexec */ +#undef BUILDID + /* whether mcoverlayfs is enabled */ #undef ENABLE_MCOVERLAYFS /* whether memdump feature is enabled */ #undef ENABLE_MEMDUMP +/* whether perf is enabled */ +#undef ENABLE_PERF + /* whether qlmpi is enabled */ #undef ENABLE_QLMPI /* whether rusage is enabled */ #undef ENABLE_RUSAGE -/* whether perf is enabled */ -#undef ENABLE_PERF - /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H diff --git a/configure b/configure index a5f44367..0e1deb85 100755 --- a/configure +++ b/configure @@ -645,6 +645,7 @@ TARGET UNAME_R KDIR ARCH +BUILDID XCC FGREP EGREP @@ -5012,6 +5013,22 @@ cat >>confdefs.h <<_ACEOF _ACEOF +ABS_SRCDIR=$( cd $( dirname $0 ); pwd ) +IHK_ABS_SRCDIR=${ABS_SRCDIR}/../ihk +{ $as_echo "$as_me:${as_lineno-$LINENO}: IHK_ABS_SRCDIR=$IHK_ABS_SRCDIR" >&5 +$as_echo "$as_me: IHK_ABS_SRCDIR=$IHK_ABS_SRCDIR" >&6;} +BUILDID=$( cd $IHK_ABS_SRCDIR; git rev-list -1 HEAD | cut -c1-8 ) +{ $as_echo "$as_me:${as_lineno-$LINENO}: BUILDID=$BUILDID" >&5 +$as_echo "$as_me: BUILDID=$BUILDID" >&6;} +if test "x$BUILDID" != "x" ; then + +cat >>confdefs.h <<_ACEOF +#define BUILDID "$BUILDID" +_ACEOF + +fi + + diff --git a/configure.ac b/configure.ac index 669ea1c3..e1f11945 100644 --- a/configure.ac +++ b/configure.ac @@ -502,6 +502,15 @@ fi AC_DEFINE_UNQUOTED(BINDIR,"$BINDIR",[Path of install directory for binary]) AC_DEFINE_UNQUOTED(SBINDIR,"$SBINDIR",[Path of install directory for system binary]) +ABS_SRCDIR=$( cd $( dirname $0 ); pwd ) +IHK_ABS_SRCDIR=${ABS_SRCDIR}/../ihk +BUILDID=$( cd $IHK_ABS_SRCDIR; git rev-list -1 HEAD | cut -c1-8 ) +AC_MSG_NOTICE([BUILDID=$BUILDID]) +if test "x$BUILDID" != "x" ; then + AC_DEFINE_UNQUOTED(BUILDID,"$BUILDID",[IHK build-id to confirm IHK and McKernel built at the same time are used]) +fi +AC_SUBST(BUILDID) + AC_SUBST(CC) AC_SUBST(XCC) AC_SUBST(ARCH) diff --git a/executer/user/Makefile.in b/executer/user/Makefile.in index 3627a1e0..5cbf3c1b 100644 --- a/executer/user/Makefile.in +++ b/executer/user/Makefile.in @@ -11,7 +11,7 @@ MCKERNEL_INCDIR=@MCKERNEL_INCDIR@ MCKERNEL_LIBDIR=@MCKERNEL_LIBDIR@ KDIR ?= @KDIR@ ARCH=@ARCH@ -CFLAGS=-Wall -O -I. -I$(VPATH)/arch/${ARCH} +CFLAGS=-Wall -O -I. -I$(VPATH)/arch/${ARCH} -I${IHKDIR} LDFLAGS=@LDFLAGS@ RPATH=$(shell echo $(LDFLAGS)|awk '{for(i=1;i<=NF;i++){if($$i~/^-L/){w=$$i;sub(/^-L/,"-Wl,-rpath,",w);print w}}}') VPATH=@abs_srcdir@ @@ -40,7 +40,7 @@ mcexec: mcexec.c libmcexec.a # POSTK_DEBUG_ARCH_DEP_34, eclair arch depend separate. ifeq ($(ARCH), arm64) eclair: eclair.c arch/$(ARCH)/arch-eclair.c - $(CC) -I.. -I. -I./arch/$(ARCH)/include -I$(VPATH)/.. -I$(VPATH) -I$(VPATH)/arch/$(ARCH)/include -I${IHKDIR} $(CFLAGS) -o $@ $^ $(LIBS) + $(CC) -I.. -I. -I./arch/$(ARCH)/include -I$(VPATH)/.. -I$(VPATH) -I$(VPATH)/arch/$(ARCH)/include $(CFLAGS) -o $@ $^ $(LIBS) else eclair: eclair.c $(CC) $(CFLAGS) -I${IHKDIR} -o $@ $^ $(LIBS) diff --git a/executer/user/mcexec.c b/executer/user/mcexec.c index 0d5b1927..28742e97 100644 --- a/executer/user/mcexec.c +++ b/executer/user/mcexec.c @@ -76,6 +76,7 @@ #include #endif /* !POSTK_DEBUG_ARCH_DEP_77 */ #include "../include/uprotocol.h" +#include #include #include "archdep.h" #include "arch_args.h" @@ -1754,6 +1755,8 @@ static int opendev() { int f; + char buildid[] = BUILDID; + char query_result[sizeof(BUILDID)]; sprintf(dev, "/dev/mcos%d", mcosid); @@ -1765,6 +1768,18 @@ opendev() } fd = f; + if (ioctl(fd, IHK_OS_GET_BUILDID, query_result)) { + fprintf(stderr, "Error: IHK_OS_GET_BUILDID failed"); + close(fd); + return -1; + } + + if (strncmp(buildid, query_result, sizeof(buildid))) { + fprintf(stderr, "Error: build-id of mcexec (%s) didn't match that of IHK (%s)\n", buildid, query_result); + close(fd); + return -1; + } + return fd; }