From patchwork Fri Jun 23 04:24:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Orson Zhai X-Patchwork-Id: 106235 Delivered-To: patch@linaro.org Received: by 10.140.91.2 with SMTP id y2csp27359qgd; Thu, 22 Jun 2017 21:24:45 -0700 (PDT) X-Received: by 10.98.29.7 with SMTP id d7mr6157677pfd.25.1498191885497; Thu, 22 Jun 2017 21:24:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498191885; cv=none; d=google.com; s=arc-20160816; b=j9sDzFRpO3ZISSEXm1/q6wOBhOAio8gjaqQZh66nGQGBpsATDKKgj5IiJhhuEb44K+ yM0Bv/VmkK3c2jNF3hFQzFRo+Kl/1ws508PM/3gxNMQLs8sfpU8/h6gEUiGOaL86/C0I vId8KaDDvC0Bqz+dg/Jbzs8C58CuQtSd4a4ormxhbOBdPbj4eOogizQuGEIcf0mV5oWa 2aDH3qzfrnQf5F7zSkDCjUVcjQpS5p9RL9o5XZR8p6d1c2FlRbHAmR5oakyr8iqJycS1 xfMf0ip33KLsxG5Fk2MyvqEYiDjkTg1/KMLojWVZu+rtLDzr//SpGCuM4KjZvsCtEmZ2 +trg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :mime-version:dkim-signature:arc-authentication-results; bh=5AhUme7ypuZxgsNPtp14rxOBdB4pmZeaXAhIET2o5No=; b=LoPwwObT004hfsTQJ0mlFD+4x6k0MK0m6YGoa561QubVg2YOtaMrYxneeBr78IMM/E tpBD4CxIFrsKvXgOmiJlwrRxnIwisS1LKifyRGkjaZ1H0+qVtbXLuYlqtMw52bK/88Cj Abnz3hgVqSJQA9NnkJsoIRaKKY54waFiLpv2dKN2axKu7wHpFoDN73tRTsCcjBzc9lty BPsw2ep8Q3IyMBXIOQhkBMbvvVpA9ufqnKwKPltafG+0Bpyu+asoTRJLFWMDyvy1jK2R 0zi1mUgqnRTpxasxLGBFzOch1EL67mOm1+4cgFz+/iTXZS4yDi55ok8Wuh7BAOFsjB/Q gr3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=imw8xDJf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f34si2804166ple.580.2017.06.22.21.24.45; Thu, 22 Jun 2017 21:24:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=imw8xDJf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751326AbdFWEYh (ORCPT + 25 others); Fri, 23 Jun 2017 00:24:37 -0400 Received: from mail-oi0-f49.google.com ([209.85.218.49]:35514 "EHLO mail-oi0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751107AbdFWEYg (ORCPT ); Fri, 23 Jun 2017 00:24:36 -0400 Received: by mail-oi0-f49.google.com with SMTP id c189so19705700oia.2 for ; Thu, 22 Jun 2017 21:24:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:from:date:message-id:subject:to:cc; bh=5AhUme7ypuZxgsNPtp14rxOBdB4pmZeaXAhIET2o5No=; b=imw8xDJfsERn+ZVVs9S/yshTlW8KrL+2Yj1qkFaxpu85E9LBw91y6uH+EjEb7NCWQc Ny86RGHLZmyecokskYNxo954e7y86kkWTdsWr1QDJY5pGPFKBVrZuWJUDU+EXLjofPoH Cjbsjov8c6DcqetCXXm/0vtptJ0ZUdAYRwNL4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=5AhUme7ypuZxgsNPtp14rxOBdB4pmZeaXAhIET2o5No=; b=dAvRR1n+OAHgLBdZJlwA3BurHNqjurCRV22OUnHTrDhhRmll60cyRCyaonR00T2o3y 0JfwWEYqSUed0x4fOew+u08p7/O4TurBqfCm3bObhUP3ktuKgGVVT8NI+l3kmrLV1cqE H1XocKyiSTSOtOrtq5hQiWgA+Mmg1+4WvaCC/XqzBaaJSErJNWfC0HnAvAnG8/mkfcxq x4ciXDQZnYFQN1oUqkODJjtnQRKLNeoAEdWtgF+wlWVQH/IiB3Fq1obConyiKzUNUOlJ K2d6xuH+Wh8xPZrBf+8SEQWwufKev9X/ow8ABkOHCsmlBsdqBDXPPDqxGNwZsnDlGnJm NgTA== X-Gm-Message-State: AKS2vOx87uiM9YKt6JhS4l/ZGCD7/LqYKmcCFLH3xCFh1wLDGt695LB/ BAo9aoN5F1AfFErc/eoi9gGul/g+RQ1Q X-Received: by 10.202.214.20 with SMTP id n20mr2234934oig.48.1498191875789; Thu, 22 Jun 2017 21:24:35 -0700 (PDT) MIME-Version: 1.0 Received: by 10.182.144.104 with HTTP; Thu, 22 Jun 2017 21:24:35 -0700 (PDT) From: Orson Zhai Date: Fri, 23 Jun 2017 12:24:35 +0800 Message-ID: Subject: [PATCH V3] tools/testing/selftests/sysctl: Add pre-check to the value of writes_strict To: Shuah Khan , Kees Cook Cc: LKML , Sumit Semwal , linux-kselftest@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sysctl test will fail in some items if the value of /proc/sys/kernel /sysctrl_writes_strict is 0 as the default value in kernel older than v4.5. Make this test more robust and compatible with older kernels by checking and update sysctrl_writes_strict value and restore it when test is done. Signed-off-by: Orson Zhai Reviewed-by: Sumit Semwal Tested-by: Sumit Semwal --- tools/testing/selftests/sysctl/common_tests | 22 ++++++++++++++++++++++ tools/testing/selftests/sysctl/run_numerictests | 2 +- tools/testing/selftests/sysctl/run_stringtests | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) -- 2.12.2 diff --git a/tools/testing/selftests/sysctl/common_tests b/tools/testing/selftests/sysctl/common_tests index 17d534b1b7b4..dfb1fcfc3142 100644 --- a/tools/testing/selftests/sysctl/common_tests +++ b/tools/testing/selftests/sysctl/common_tests @@ -24,6 +24,14 @@ verify() return 0 } +exit_test() +{ + if [ ! -z ${old_strict} ]; then + echo ${old_strict} > ${WRITES_STRICT} + fi + exit $rc +} + trap 'set_orig; rm -f "${TEST_FILE}"' EXIT rc=0 @@ -63,6 +71,20 @@ else echo "ok" fi +echo -n "Checking write strict setting ... " +WRITES_STRICT="${SYSCTL}/kernel/sysctl_writes_strict" +if [ ! -e ${WRITES_STRICT} ]; then + echo "FAIL, but skip in case of old kernel" >&2 +else + old_strict=$(cat ${WRITES_STRICT}) + if [ "$old_strict" = "1" ]; then + echo "ok" + else + echo "FAIL, strict value is 0 but force to 1 to continue" >&2 + echo "1" > ${WRITES_STRICT} + fi +fi + # Now that we've validated the sanity of "set_test" and "set_orig", # we can use those functions to set starting states before running # specific behavioral tests. diff --git a/tools/testing/selftests/sysctl/run_numerictests b/tools/testing/selftests/sysctl/run_numerictests index 8510f93f2d14..e6e76c93d948 100755 --- a/tools/testing/selftests/sysctl/run_numerictests +++ b/tools/testing/selftests/sysctl/run_numerictests @@ -7,4 +7,4 @@ TEST_STR=$(( $ORIG + 1 )) . ./common_tests -exit $rc +exit_test diff --git a/tools/testing/selftests/sysctl/run_stringtests b/tools/testing/selftests/sysctl/run_stringtests index 90a9293d520c..857ec667fb02 100755 --- a/tools/testing/selftests/sysctl/run_stringtests +++ b/tools/testing/selftests/sysctl/run_stringtests @@ -74,4 +74,4 @@ else echo "ok" fi -exit $rc +exit_test