From patchwork Mon Jul 26 15:17:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Doucha X-Patchwork-Id: 1510108 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=YZwt2wCm; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=vrIGiQCP; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GYNpy5N6Rz9sRR for ; Tue, 27 Jul 2021 01:18:18 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 943183C9247 for ; Mon, 26 Jul 2021 17:18:16 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [217.194.8.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 980CA3C6615 for ; Mon, 26 Jul 2021 17:18:05 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id D953E1000A16 for ; Mon, 26 Jul 2021 17:18:04 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 1159921F60 for ; Mon, 26 Jul 2021 15:18:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1627312684; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=CXVtyfTSPNeo9/YSMMiicAbkLUFVKKRTnaXZseSuN+o=; b=YZwt2wCmENdI+HQ3szZHvPg0nXc4tHOhpMPWLlgeHeOHsbyC/scXm3o0grmTcRkTJQko2O QonyrI2E5CJqHwQm45TstvSRKTS4zFN3RhbMPBMS50lDuNM0BnygoF2gcz6lkaiuZe2Svm ttM0coVXoIVajaiwjFutYs2pT7bL1tI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1627312684; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=CXVtyfTSPNeo9/YSMMiicAbkLUFVKKRTnaXZseSuN+o=; b=vrIGiQCPGI78Bo1pLW/sO53AFp1aYGJPc8aNLcJXrcb4wMxdHYxZ5AaJM16p3Juj4B8AjM HCkQRUQp6Us93LDQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id F335F13AA2 for ; Mon, 26 Jul 2021 15:18:03 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id oCp5OivS/mAZYgAAMHmgww (envelope-from ) for ; Mon, 26 Jul 2021 15:18:03 +0000 From: Martin Doucha To: ltp@lists.linux.it Date: Mon, 26 Jul 2021 17:17:35 +0200 Message-Id: <20210726151736.14299-1-mdoucha@suse.cz> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH 1/2] Add tst_hexdump utility X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" tst_hexdump implements conversion between binary and hexadecimal values in both directions for shell tests. Signed-off-by: Martin Doucha Reviewed-by: Petr Vorel --- testcases/lib/Makefile | 2 +- testcases/lib/tst_hexdump.c | 55 +++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 testcases/lib/tst_hexdump.c diff --git a/testcases/lib/Makefile b/testcases/lib/Makefile index 98d9e4613..38813e640 100644 --- a/testcases/lib/Makefile +++ b/testcases/lib/Makefile @@ -11,6 +11,6 @@ INSTALL_TARGETS := *.sh MAKE_TARGETS := tst_sleep tst_random tst_checkpoint tst_rod tst_kvcmp\ tst_device tst_net_iface_prefix tst_net_ip_prefix tst_net_vars\ tst_getconf tst_supported_fs tst_check_drivers tst_get_unused_port\ - tst_get_median + tst_get_median tst_hexdump include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/lib/tst_hexdump.c b/testcases/lib/tst_hexdump.c new file mode 100644 index 000000000..f83b8bfbf --- /dev/null +++ b/testcases/lib/tst_hexdump.c @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2021 SUSE LLC + * + * Convert bytes from standard input to hexadecimal representation. + * + * Parameters: + * -d Convert hexadecimal values from standard input to binary representation + * instead. + */ + +#include +#include + +int decode_hex(void) +{ + int ret; + unsigned int val; + + while ((ret = scanf("%2x", &val)) == 1) + putchar(val); + + return ret != EOF || ferror(stdin); +} + +int encode_hex(void) +{ + int val; + + for (val = getchar(); val >= 0 && val <= 0xff; val = getchar()) + printf("%02x", val); + + return val != EOF || ferror(stdin); +} + +int main(int argc, char **argv) +{ + int ret, decode = 0; + + while ((ret = getopt(argc, argv, "d"))) { + if (ret < 0) + break; + + switch (ret) { + case 'd': + decode = 1; + break; + } + } + + if (decode) + return decode_hex(); + else + return encode_hex(); +} From patchwork Mon Jul 26 15:17:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Doucha X-Patchwork-Id: 1510107 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=R/dfx7g9; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=k702p/kr; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GYNpr5Tbpz9sRR for ; Tue, 27 Jul 2021 01:18:11 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 598663C9225 for ; Mon, 26 Jul 2021 17:18:07 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [IPv6:2001:4b78:1:20::5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 5F4D03C6615 for ; Mon, 26 Jul 2021 17:18:05 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id CD24660069B for ; Mon, 26 Jul 2021 17:18:04 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 266901FD34 for ; Mon, 26 Jul 2021 15:18:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1627312684; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2P0hdKwo2SAFX5f7E5BVqieCNSutF/WLfX7pCl6Cq/I=; b=R/dfx7g9A94SnPgBaHnFvaJkKI37VROMypluzcLT7ZKSzQhn294uBkfRUr3Pd+UFEvHEYA 366ELTv8HUHdDOnmnHlq7+hT3WMjX7xgvPSXb0Jn6MJIy6G2GyIRBTxPQ0spQ/E9VhqUMS PhP+5/xpvQsOf7hgl5ljCC8H6R8sLJE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1627312684; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2P0hdKwo2SAFX5f7E5BVqieCNSutF/WLfX7pCl6Cq/I=; b=k702p/krCP5iO1T2CRu5MBEmwxYeJJ8YXI55EN4vyXbrGziEBlgyV1is+JJXotBuLFXad6 v+wE7qin700wzsCw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 14E5013B43 for ; Mon, 26 Jul 2021 15:18:04 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id sJMXBCzS/mAZYgAAMHmgww (envelope-from ) for ; Mon, 26 Jul 2021 15:18:04 +0000 From: Martin Doucha To: ltp@lists.linux.it Date: Mon, 26 Jul 2021 17:17:36 +0200 Message-Id: <20210726151736.14299-2-mdoucha@suse.cz> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210726151736.14299-1-mdoucha@suse.cz> References: <20210726151736.14299-1-mdoucha@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-5.smtp.seeweb.it Subject: [LTP] [PATCH 2/2] Replace the xxd utility with tst_hexdump X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" The xxd utility is part of Vim suite and may not be available on embedded systems. Replace it with internal LTP helper program. Signed-off-by: Martin Doucha --- Note: I couldn't test ima_selinux.sh changes because SLES kernel don't support measure func=CRITICAL_DATA yet. ima_keys.sh appears to work correctly. testcases/kernel/security/integrity/ima/tests/ima_keys.sh | 6 +++--- .../kernel/security/integrity/ima/tests/ima_selinux.sh | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/testcases/kernel/security/integrity/ima/tests/ima_keys.sh b/testcases/kernel/security/integrity/ima/tests/ima_keys.sh index 3476b8007..995a55fed 100755 --- a/testcases/kernel/security/integrity/ima/tests/ima_keys.sh +++ b/testcases/kernel/security/integrity/ima/tests/ima_keys.sh @@ -6,7 +6,7 @@ # # Verify that keys are measured correctly based on policy. -TST_NEEDS_CMDS="cmp cut grep sed xxd" +TST_NEEDS_CMDS="cmp cut grep sed" TST_CNT=2 TST_NEEDS_DEVICE=1 TST_SETUP=setup @@ -82,7 +82,7 @@ test1() algorithm=$(echo "$line" | cut -d' ' -f4 | cut -d':' -f1) keyring=$(echo "$line" | cut -d' ' -f5) - echo "$line" | cut -d' ' -f6 | xxd -r -p > $test_file + echo "$line" | cut -d' ' -f6 | tst_hexdump -d > $test_file if ! expected_digest="$(compute_digest $algorithm $test_file)"; then tst_res TCONF "cannot compute digest for $algorithm" @@ -126,7 +126,7 @@ test2() tst_brk TBROK "unable to import a certificate into $keyring_name keyring" grep $keyring_name $ASCII_MEASUREMENTS | tail -n1 | cut -d' ' -f6 | \ - xxd -r -p > $temp_file + tst_hexdump -d > $temp_file if [ ! -s $temp_file ]; then tst_res TFAIL "keyring $keyring_name not found in $ASCII_MEASUREMENTS" diff --git a/testcases/kernel/security/integrity/ima/tests/ima_selinux.sh b/testcases/kernel/security/integrity/ima/tests/ima_selinux.sh index c2af0e298..a4eb60b16 100755 --- a/testcases/kernel/security/integrity/ima/tests/ima_selinux.sh +++ b/testcases/kernel/security/integrity/ima/tests/ima_selinux.sh @@ -100,8 +100,6 @@ test1() # configuration. test2() { - tst_check_cmds xxd || return - local measured_data state_file="$TST_TMPDIR/selinux_state.txt" local data_source_name="selinux" local pattern="data_sources=[^[:space:]]*$data_source_name" @@ -127,7 +125,7 @@ test2() digest=$(echo "$line" | cut -d' ' -f4 | cut -d':' -f2) algorithm=$(echo "$line" | cut -d' ' -f4 | cut -d':' -f1) - echo "$line" | cut -d' ' -f6 | xxd -r -p > $state_file + echo "$line" | cut -d' ' -f6 | tst_hexdump -d > $state_file expected_digest="$(compute_digest $algorithm $state_file)" || \ tst_brk TCONF "cannot compute digest for $algorithm"