From patchwork Fri Jun 23 04:19:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Orson Zhai X-Patchwork-Id: 106234 Delivered-To: patch@linaro.org Received: by 10.140.91.2 with SMTP id y2csp26094qgd; Thu, 22 Jun 2017 21:19:38 -0700 (PDT) X-Received: by 10.84.135.1 with SMTP id 1mr6867208pli.185.1498191578617; Thu, 22 Jun 2017 21:19:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498191578; cv=none; d=google.com; s=arc-20160816; b=McrWcf3t8kg37iw+YlVLWkXRX45sA7gV7T01kVYkY2kE183M8ksF+HKWiQW6PgzSw5 ghb26OaN8i5ay8dGZbCtcGqiru7Ht93K9hUkfDIUNFu5tcPaq4AyUo69p55wraVKkgMz gAQLZASgQhz927yD0l0+zhxltUcFSgSz9VDcJjKaUH8Wy3sW9TOUj1z6x8OLUrxxxpUv ukRtCiM/mD/Xzhsphi1cu6+CvK7WgiuzTKV92tDDLOoVMRJmMyUDFsqZUY57M7vgRiNQ vOOgpgDCRHyXbr0FReCrsUfX8QrZ7vnikSv0++OOCF1lQADz925dA6ubArBqhfu+8i3o Ifxw== 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 :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=SZj1ZctCEb6AxjgPh839c4fJmpuY7OF8zkJOj/ZT27E=; b=vZVKEeZOKhXytspvDfGT5OKTOMvpf1eLAJfRmz3hHNwvJgjE6dCzI3LVPa2jVmNmvb sGD5J534Dcqz3W4GKlQ8FFZfxyGXatW6fSYkkNI8/78PY4b6U6eu8HHPEHbYqygg6SV6 F9/MO6uqNj2jOcvh3dnKd+RNSLzV+lS7j/2eU0Mqtm6WjyTA0mLtr+Qv9zJTzbrji9sh /p/UXx+9gOoCK4f/ZqKIIJ/gU0evkPcll5tIOmmnoMg+fWw8iz9JfdQfYOOUY8kQA5VT MTQlfaL/1C9NinNWac2H08PYXneteWXwbnRfKm2xLsOW2SYq4sH7MUzR9sDmtUxBOqqy ggMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=RyoF+osK; 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 f25si2516108pff.403.2017.06.22.21.19.38; Thu, 22 Jun 2017 21:19:38 -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=RyoF+osK; 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 S1754126AbdFWETQ (ORCPT + 25 others); Fri, 23 Jun 2017 00:19:16 -0400 Received: from mail-oi0-f51.google.com ([209.85.218.51]:32915 "EHLO mail-oi0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751169AbdFWETO (ORCPT ); Fri, 23 Jun 2017 00:19:14 -0400 Received: by mail-oi0-f51.google.com with SMTP id p66so19604603oia.0 for ; Thu, 22 Jun 2017 21:19:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=SZj1ZctCEb6AxjgPh839c4fJmpuY7OF8zkJOj/ZT27E=; b=RyoF+osKm+wq0d8/GKGh3apGLWqLO3Pg8kFuuZXfswsjuu9Cd6HEvG+swlay3C2fjv CRNE9j7e4ykVrXejEKmgEZ5sVcJPL9kipLfZUzK4hlQDEjMAZhe+DqQdhdudMyBXVCJa gGOYOwvuwqXwzorEEYvrTsUU6PZYYt3OQxd8E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=SZj1ZctCEb6AxjgPh839c4fJmpuY7OF8zkJOj/ZT27E=; b=iii5LomEyDJsyku6yYGH8W2FJoRXIavO8CcK3g2LOmYGQn1eeWj+bRy/KMm85+qmT/ 82nXKy0PtdrVJY/ZvI9/5CpywxURUI42TUNx9famHA9pz8C+8p+H3aiTNJlH6fpebJZQ M99T2XVZ/bLM5gCkpFCIwQsb6HkkuNYsi/xlbObCpjXMpSZWOPGDTgXyjoooFqsFfMVY 5JX8VEgb+VpSZuA+qGAj/3HhIkyVMAIj/IQwNiBPVaFGqEVaCqQKWuCTt7zcRxDT6ReM EXG6Xlti2A/8onlmf1HOYR7K1ZOAX1egSBoofEuejnrxyVtszRw/PrxBw+Kt0koYQ30p YFOA== X-Gm-Message-State: AKS2vOz1g8zYLRcEpWoJdwKf+6VIwSqJMXAFtfK/5568uR2haVQM6WKM knXqK12SNYVvP0CEr+eyqPq/thkRbHq4 X-Received: by 10.202.63.133 with SMTP id m127mr2955265oia.55.1498191553761; Thu, 22 Jun 2017 21:19:13 -0700 (PDT) MIME-Version: 1.0 Received: by 10.182.144.104 with HTTP; Thu, 22 Jun 2017 21:19:13 -0700 (PDT) In-Reply-To: <20170623035911.6191-1-orson.zhai@spreadtrum.com> References: <20170623035911.6191-1-orson.zhai@spreadtrum.com> From: Orson Zhai Date: Fri, 23 Jun 2017 12:19:13 +0800 Message-ID: Subject: Fwd: [PATCH V2] 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 failed in some items if the value of /proc/sys/kernel /sysctrl_writes_strict is 0 as the default value in kernel older than v4.6. Make this test more robus and compatible with older kernel by checking and update 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