From patchwork Wed Mar 20 22:28:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 10862659 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C7E841390 for ; Wed, 20 Mar 2019 22:28:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD9DF29ECD for ; Wed, 20 Mar 2019 22:28:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A17BB29ED1; Wed, 20 Mar 2019 22:28:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C11A29ECD for ; Wed, 20 Mar 2019 22:28:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727658AbfCTW2s (ORCPT ); Wed, 20 Mar 2019 18:28:48 -0400 Received: from mail-yw1-f68.google.com ([209.85.161.68]:44685 "EHLO mail-yw1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727540AbfCTW2r (ORCPT ); Wed, 20 Mar 2019 18:28:47 -0400 Received: by mail-yw1-f68.google.com with SMTP id c4so3315616ywa.11; Wed, 20 Mar 2019 15:28:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8Uoy8NZffLtwCVWkJYoNixcTf+BuPJo1nSiGzd+WLLk=; b=HYXZtfIxu3Krjp/OwZozZHWgEQdAIqbLGS3QNDkkHsuZ3lonzgeudzkbi/dTHqKR2x +2Xnx03DPyAk3ja069TSEZ3B887LfTG3MuuamCMKHe2oHDvq9E2WAYbUbO6C9Dtk+RJK Lzc5vqN0lJTyp/zUhveRmZjb3eT6BfZV0MhIQXAjeU76DtomeB0TT941ZlM3sfo+h83N mbrMs7qiDs4edzTLjjCVid2RvpVVYP3Do1bV1RrmnLCmOuz3bG8bRwG1fK1tM8O8zGKU 0V2AlzXHCLMfTfABFSxQ/2YpucTcT55B5P/auU1BvwfYHJqSRI8QlwhPRQnEMZqx+6Zf T/UQ== X-Gm-Message-State: APjAAAXb5ivhrQbwGH1PgT2Nk32a0lpcR3N++1qsrB4sltaVhp4xUVxy ZZ5Sr7sfgrcdkBRxkIfRXbL78eVZZH0= X-Google-Smtp-Source: APXvYqxk+AZOaDH/Ah5XbLTmukG4DqBUEwZhwi6JjfpO5RGxWEzidqkzkQN/8/pw/36mVekf2YEHUA== X-Received: by 2002:a5b:9cf:: with SMTP id y15mr358887ybq.324.1553120926743; Wed, 20 Mar 2019 15:28:46 -0700 (PDT) Received: from 42.do-not-panic.com (42.do-not-panic.com. [157.230.128.187]) by smtp.gmail.com with ESMTPSA id 207sm1148726yws.38.2019.03.20.15.28.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Mar 2019 15:28:45 -0700 (PDT) Received: by 42.do-not-panic.com (sSMTP sendmail emulation); Wed, 20 Mar 2019 22:28:43 +0000 From: Luis Chamberlain To: akpm@linux-foundation.org, keescook@chromium.org Cc: sandeen@redhat.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Luis Chamberlain Subject: [PATCH 1/6] test_sysctl: remove superfluous test_reqs() Date: Wed, 20 Mar 2019 22:28:26 +0000 Message-Id: <20190320222831.8243-2-mcgrof@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190320222831.8243-1-mcgrof@kernel.org> References: <20190320222831.8243-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We already call test_reqs(), no need to call it twice. Signed-off-by: Luis Chamberlain --- tools/testing/selftests/sysctl/sysctl.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/testing/selftests/sysctl/sysctl.sh b/tools/testing/selftests/sysctl/sysctl.sh index 780ce7123374..87df7e52a97a 100755 --- a/tools/testing/selftests/sysctl/sysctl.sh +++ b/tools/testing/selftests/sysctl/sysctl.sh @@ -675,8 +675,6 @@ list_tests() echo "0005 x $(get_test_count 0005) - tests proc_douintvec() array" } -test_reqs - usage() { NUM_TESTS=$(grep -o ' ' <<<"$ALL_TESTS" | grep -c .) From patchwork Wed Mar 20 22:28:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 10862661 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DE95E1515 for ; Wed, 20 Mar 2019 22:28:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C297429ED0 for ; Wed, 20 Mar 2019 22:28:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B763829ED4; Wed, 20 Mar 2019 22:28:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D81D29ED0 for ; Wed, 20 Mar 2019 22:28:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727684AbfCTW2y (ORCPT ); Wed, 20 Mar 2019 18:28:54 -0400 Received: from mail-yw1-f66.google.com ([209.85.161.66]:46078 "EHLO mail-yw1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727680AbfCTW2v (ORCPT ); Wed, 20 Mar 2019 18:28:51 -0400 Received: by mail-yw1-f66.google.com with SMTP id j128so3315034ywg.12; Wed, 20 Mar 2019 15:28:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7xNmYnQsl8UJtiV0CU/tgLUrv0vvHpQBBgA3eiMC6KQ=; b=VZyIhzg/vL7xRCsLheE8ezlNVmYdhnoRtp/zpMun8NOvCiC3/IYUi7P/lVY9KiG3CM aTT5GR7c/J12w9xVRmTTEeYQ46k8oq2yeFnJDoMtM5JV8tkShQfFZ41jcMLde2Yvzl37 +WZ5MMc7F0xsyXwaqivYi9mzpZJddkEtxy2Wdj5P5ZM6QnJthUpppm8Zx7pbj+Bk1iDE FtEecxkgGXuZAHtJ22/iLLylMhOLQgufvP/sju0+KvA3XeIEsvDhAIul+5cG5pN8khsJ NT3joBqauU5c3d2W/wps7QWxDAGxDkzEjzHljYFg/MRyXrFxVhCE2APHPR/ywmjerRgS lmbw== X-Gm-Message-State: APjAAAVJSLjE9xK7ykIR1IU/FoiD/FpH/6BsMKDbuCJlpRVX0pfxxeQI Xwv/iUj25HIG4ooeOWttYeI= X-Google-Smtp-Source: APXvYqyK/6Ghd74kvYhCkKGbDwRh2ZfNdWJRPzBbtXfcu+i+DL6vWjisPUBWHmWGp/QQGjsTN0zCtA== X-Received: by 2002:a25:dd8:: with SMTP id 207mr291070ybn.379.1553120929839; Wed, 20 Mar 2019 15:28:49 -0700 (PDT) Received: from 42.do-not-panic.com (42.do-not-panic.com. [157.230.128.187]) by smtp.gmail.com with ESMTPSA id p17sm1067949ywg.27.2019.03.20.15.28.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Mar 2019 15:28:49 -0700 (PDT) Received: by 42.do-not-panic.com (sSMTP sendmail emulation); Wed, 20 Mar 2019 22:28:46 +0000 From: Luis Chamberlain To: akpm@linux-foundation.org, keescook@chromium.org Cc: sandeen@redhat.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Luis Chamberlain Subject: [PATCH 2/6] test_sysctl: load module before testing for it Date: Wed, 20 Mar 2019 22:28:27 +0000 Message-Id: <20190320222831.8243-3-mcgrof@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190320222831.8243-1-mcgrof@kernel.org> References: <20190320222831.8243-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently the test script checks for the existance of the sysctl test module's directory path prior to loading it. We must first try to load the module prior to checking for that path. This fixes the order for the load / test. Signed-off-by: Luis Chamberlain --- tools/testing/selftests/sysctl/sysctl.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/sysctl/sysctl.sh b/tools/testing/selftests/sysctl/sysctl.sh index 87df7e52a97a..e0c8404da6b0 100755 --- a/tools/testing/selftests/sysctl/sysctl.sh +++ b/tools/testing/selftests/sysctl/sysctl.sh @@ -823,8 +823,8 @@ function parse_args() test_reqs allow_user_defaults check_production_sysctl_writes_strict -test_modprobe load_req_mod +test_modprobe trap "test_finish" EXIT From patchwork Wed Mar 20 22:28:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 10862669 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 924131515 for ; Wed, 20 Mar 2019 22:29:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 789F329E50 for ; Wed, 20 Mar 2019 22:29:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6D0C529ED8; Wed, 20 Mar 2019 22:29:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DC7E29E50 for ; Wed, 20 Mar 2019 22:29:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727689AbfCTW2z (ORCPT ); Wed, 20 Mar 2019 18:28:55 -0400 Received: from mail-yw1-f67.google.com ([209.85.161.67]:33432 "EHLO mail-yw1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727540AbfCTW2y (ORCPT ); Wed, 20 Mar 2019 18:28:54 -0400 Received: by mail-yw1-f67.google.com with SMTP id a199so3375556ywa.0; Wed, 20 Mar 2019 15:28:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Bx9EJikvDMDGUCNAwxp4SdiC4KEOqeo4PV+oxcc7bOY=; b=IasSFqtBfIra77EMpkfxc+vdxCG82hYuduGtDF/TNWQ0ZJXOQkWGcnipX9QvepY8RW MNFb/PVGRWtnZ7NASrbvA6jNXSazF3IYKhHeIjSnJgtD8ZVMWOfhHHjxanWO26vaRdis WmLjNGtooFwrcBIcosIuh0DAoL6H3XPoUvTw7yqccvFIioo1bk2AKvZLPrgjx97Dh6GU XMUAydm3dzL/CoIdTepa1lzwxZ2kkGFGokAFnzhxlQRhdOzALMclPvbiqx613g0/CNV9 8lxNd0WgkmT5h/m7bp9di3185ve0rRclBhJxgEwm5E8GRHxEyZtscesh2eYBJVoKvhgY m7Pw== X-Gm-Message-State: APjAAAV908AyDKKe+cFaATdxk6+QywxiTlDnduIOpftEZzJqOLaBRT+s FXN6BvLQ+JinvKbTQlvjffg= X-Google-Smtp-Source: APXvYqwB1B3dKfMqnsDAG+nmoEINKciwiZmKc32r/lIlls0no3VQOd2mh4fBVo4UDYofa2t3eVLq9g== X-Received: by 2002:a25:65d4:: with SMTP id z203mr345117ybb.370.1553120933151; Wed, 20 Mar 2019 15:28:53 -0700 (PDT) Received: from 42.do-not-panic.com (42.do-not-panic.com. [157.230.128.187]) by smtp.gmail.com with ESMTPSA id p1sm1067327ywg.12.2019.03.20.15.28.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Mar 2019 15:28:52 -0700 (PDT) Received: by 42.do-not-panic.com (sSMTP sendmail emulation); Wed, 20 Mar 2019 22:28:49 +0000 From: Luis Chamberlain To: akpm@linux-foundation.org, keescook@chromium.org Cc: sandeen@redhat.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Luis Chamberlain Subject: [PATCH 3/6] test_sysctl: ignore diff output on verify_diff_w() Date: Wed, 20 Mar 2019 22:28:28 +0000 Message-Id: <20190320222831.8243-4-mcgrof@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190320222831.8243-1-mcgrof@kernel.org> References: <20190320222831.8243-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When verify_diff_w() is used we care about the result, not the verbose output, and although we use -q, that still gives us a chatty message about if the files differ or not. Since verify_diff_w() uses stdinput the chatty message says whether or not "-" matches the target file, and this just seems rather odd. Better to just ignore that messsage all together, what we really care about i sthe results, the return value and we check for that. Signed-off-by: Luis Chamberlain --- tools/testing/selftests/sysctl/sysctl.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/sysctl/sysctl.sh b/tools/testing/selftests/sysctl/sysctl.sh index e0c8404da6b0..f51987d0d32d 100755 --- a/tools/testing/selftests/sysctl/sysctl.sh +++ b/tools/testing/selftests/sysctl/sysctl.sh @@ -179,7 +179,7 @@ verify() verify_diff_w() { - echo "$TEST_STR" | diff -q -w -u - $1 + echo "$TEST_STR" | diff -q -w -u - $1 > /dev/null return $? } From patchwork Wed Mar 20 22:28:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 10862667 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8ED811515 for ; Wed, 20 Mar 2019 22:29:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6888729E50 for ; Wed, 20 Mar 2019 22:29:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5CECD29ED8; Wed, 20 Mar 2019 22:29:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCB7729E50 for ; Wed, 20 Mar 2019 22:29:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727719AbfCTW27 (ORCPT ); Wed, 20 Mar 2019 18:28:59 -0400 Received: from mail-yw1-f67.google.com ([209.85.161.67]:39883 "EHLO mail-yw1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727716AbfCTW26 (ORCPT ); Wed, 20 Mar 2019 18:28:58 -0400 Received: by mail-yw1-f67.google.com with SMTP id z191so3339196ywa.6; Wed, 20 Mar 2019 15:28:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=K7em68x27KVg9+yc6N9BqQ31VLJPqpShkJ9qkC4J32Y=; b=NtmmrQ3m8umoh52dsjo6xZFolBeJsI5ZE5l1hWpSYboTc7+IxZbFsBWY8bMHqEWIOA 6MtY6xnzWcbguzHZERG0pVzSeF+N1BjlFPOq4pa8bfdbzKHXkMJwv1J6Xjovk9YeirDJ OSTL6fbWG/lRV4NdyC2GDgIufcjc7wbFGTNlfUD2Xc0FOho89frPD/+q9Vh6IhMWsXXT zMlaXY3hyJtZ+6O11XEln5wVAA51zZtzWErYoETvXBlCody5KNyHrq4Hu047Dxaz7skn 57Tajcf5jjtlcPLY8lzkOPB9OOUBbTyaClJhqP/SKLKpdpT6XkORCzZ+zK4rQtq2ClyN xukg== X-Gm-Message-State: APjAAAVXuXbm3Wi2A2/KGgdK5qbpy4e9LvcjUczwNPq9LZoXcmQ9NxXV 6gK8mpcPTLINDCxoZYIK2B4= X-Google-Smtp-Source: APXvYqy/mlD2puc8urYPUmdhhZXPc1hHSwMvCMLYYr7oSUYm3tkrry4r76PeMXDh5RzItfotl0gYiQ== X-Received: by 2002:a81:9bc6:: with SMTP id s189mr417713ywg.431.1553120936434; Wed, 20 Mar 2019 15:28:56 -0700 (PDT) Received: from 42.do-not-panic.com (42.do-not-panic.com. [157.230.128.187]) by smtp.gmail.com with ESMTPSA id i126sm1102971ywa.29.2019.03.20.15.28.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Mar 2019 15:28:55 -0700 (PDT) Received: by 42.do-not-panic.com (sSMTP sendmail emulation); Wed, 20 Mar 2019 22:28:53 +0000 From: Luis Chamberlain To: akpm@linux-foundation.org, keescook@chromium.org Cc: sandeen@redhat.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Luis Chamberlain Subject: [PATCH 4/6] test_sysctl: allow graceful use on older kernels Date: Wed, 20 Mar 2019 22:28:29 +0000 Message-Id: <20190320222831.8243-5-mcgrof@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190320222831.8243-1-mcgrof@kernel.org> References: <20190320222831.8243-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On old kernels older new test knobs implemented on the test_sysctl module may not be available. This is expected, and the selftests test scripts should be able to run without failures on older kernels. Generalize a solution so that we test for each required test target file for each test by requiring each test description to annotate their respective test target file. If the target file does not exist, we skip the test gracefully. Signed-off-by: Luis Chamberlain --- tools/testing/selftests/sysctl/sysctl.sh | 78 ++++++++++++++++-------- 1 file changed, 53 insertions(+), 25 deletions(-) diff --git a/tools/testing/selftests/sysctl/sysctl.sh b/tools/testing/selftests/sysctl/sysctl.sh index f51987d0d32d..4eb019068e24 100755 --- a/tools/testing/selftests/sysctl/sysctl.sh +++ b/tools/testing/selftests/sysctl/sysctl.sh @@ -24,19 +24,20 @@ TEST_FILE=$(mktemp) # This represents # -# TEST_ID:TEST_COUNT:ENABLED +# TEST_ID:TEST_COUNT:ENABLED:TARGET # # TEST_ID: is the test id number # TEST_COUNT: number of times we should run the test # ENABLED: 1 if enabled, 0 otherwise +# TARGET: test target file required on the test_sysctl module # # Once these are enabled please leave them as-is. Write your own test, # we have tons of space. -ALL_TESTS="0001:1:1" -ALL_TESTS="$ALL_TESTS 0002:1:1" -ALL_TESTS="$ALL_TESTS 0003:1:1" -ALL_TESTS="$ALL_TESTS 0004:1:1" -ALL_TESTS="$ALL_TESTS 0005:3:1" +ALL_TESTS="0001:1:1:int_0001" +ALL_TESTS="$ALL_TESTS 0002:1:1:string_0001" +ALL_TESTS="$ALL_TESTS 0003:1:1:int_0002" +ALL_TESTS="$ALL_TESTS 0004:1:1:uint_0001" +ALL_TESTS="$ALL_TESTS 0005:3:1:int_0003" test_modprobe() { @@ -157,8 +158,10 @@ reset_vals() set_orig() { - if [ ! -z $TARGET ]; then - echo "${ORIG}" > "${TARGET}" + if [ ! -z $TARGET ] && [ ! -z $ORIG ]; then + if [ -f ${TARGET} ]; then + echo "${ORIG}" > "${TARGET}" + fi fi } @@ -600,9 +603,21 @@ run_stringtests() test_rc } +target_exists() +{ + TARGET="${SYSCTL}/$1" + TEST_ID="$2" + + if [ ! -f ${TARGET} ] ; then + echo "Target for test $TEST_ID: $TARGET not exist, skipping test ..." + return 0 + fi + return 1 +} + sysctl_test_0001() { - TARGET="${SYSCTL}/int_0001" + TARGET="${SYSCTL}/$(get_test_target 0001)" reset_vals ORIG=$(cat "${TARGET}") TEST_STR=$(( $ORIG + 1 )) @@ -614,7 +629,7 @@ sysctl_test_0001() sysctl_test_0002() { - TARGET="${SYSCTL}/string_0001" + TARGET="${SYSCTL}/$(get_test_target 0002)" reset_vals ORIG=$(cat "${TARGET}") TEST_STR="Testing sysctl" @@ -627,7 +642,7 @@ sysctl_test_0002() sysctl_test_0003() { - TARGET="${SYSCTL}/int_0002" + TARGET="${SYSCTL}/$(get_test_target 0003)" reset_vals ORIG=$(cat "${TARGET}") TEST_STR=$(( $ORIG + 1 )) @@ -640,7 +655,7 @@ sysctl_test_0003() sysctl_test_0004() { - TARGET="${SYSCTL}/uint_0001" + TARGET="${SYSCTL}/$(get_test_target 0004)" reset_vals ORIG=$(cat "${TARGET}") TEST_STR=$(( $ORIG + 1 )) @@ -653,7 +668,7 @@ sysctl_test_0004() sysctl_test_0005() { - TARGET="${SYSCTL}/int_0003" + TARGET="${SYSCTL}/$(get_test_target 0005)" reset_vals ORIG=$(cat "${TARGET}") @@ -722,25 +737,36 @@ function get_test_count() { test_num $1 TEST_DATA=$(echo $ALL_TESTS | awk '{print $'$1'}') - LAST_TWO=${TEST_DATA#*:*} - echo ${LAST_TWO%:*} + echo ${TEST_DATA} | awk -F":" '{print $2}' } function get_test_enabled() { test_num $1 TEST_DATA=$(echo $ALL_TESTS | awk '{print $'$1'}') - echo ${TEST_DATA#*:*:} + echo ${TEST_DATA} | awk -F":" '{print $3}' +} + +function get_test_target() +{ + test_num $1 + TEST_DATA=$(echo $ALL_TESTS | awk '{print $'$1'}') + echo ${TEST_DATA} | awk -F":" '{print $4}' } function run_all_tests() { for i in $ALL_TESTS ; do - TEST_ID=${i%:*:*} + TEST_ID=${i%:*:*:*} ENABLED=$(get_test_enabled $TEST_ID) TEST_COUNT=$(get_test_count $TEST_ID) + TEST_TARGET=$(get_test_target $TEST_ID) + target_exists $TEST_TARGET $TEST_ID + if [ $? -ne 1 ]; then + continue + fi if [[ $ENABLED -eq "1" ]]; then - test_case $TEST_ID $TEST_COUNT + test_case $TEST_ID $TEST_COUNT $TEST_TARGET fi done } @@ -773,12 +799,14 @@ function watch_case() function test_case() { - NUM_TESTS=$DEFAULT_NUM_TESTS - if [ $# -eq 2 ]; then - NUM_TESTS=$2 - fi + NUM_TESTS=$2 i=0 + + if target_exists $3 $1; then + continue + fi + while [ $i -lt $NUM_TESTS ]; do test_num $1 watch_log $i ${TEST_NAME}_test_$1 noclear @@ -801,15 +829,15 @@ function parse_args() elif [[ "$1" = "-t" ]]; then shift test_num $1 - test_case $1 $(get_test_count $1) + test_case $1 $(get_test_count $1) $(get_test_target $1) elif [[ "$1" = "-c" ]]; then shift test_num $1 test_num $2 - test_case $1 $2 + test_case $1 $2 $(get_test_target $1) elif [[ "$1" = "-s" ]]; then shift - test_case $1 1 + test_case $1 1 $(get_test_target $1) elif [[ "$1" = "-l" ]]; then list_tests elif [[ "$1" = "-h" || "$1" = "--help" ]]; then From patchwork Wed Mar 20 22:28:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 10862665 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 903D31390 for ; Wed, 20 Mar 2019 22:29:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 700CC29E50 for ; Wed, 20 Mar 2019 22:29:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 642AF29ED8; Wed, 20 Mar 2019 22:29:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C32C729E50 for ; Wed, 20 Mar 2019 22:29:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727739AbfCTW3C (ORCPT ); Wed, 20 Mar 2019 18:29:02 -0400 Received: from mail-yw1-f66.google.com ([209.85.161.66]:35556 "EHLO mail-yw1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727564AbfCTW3B (ORCPT ); Wed, 20 Mar 2019 18:29:01 -0400 Received: by mail-yw1-f66.google.com with SMTP id d132so3364221ywa.2; Wed, 20 Mar 2019 15:29:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZXLEDnmHDPhD+gAeHfoEQ/h6E/FKMiQK/iYleyKhCCg=; b=CUOTovZRb9aTz3mlJAiVVBkSPpfmd1D70JSrUqf0hJ6dUUxMcKL31D9i9bg20blEnP JBrsGGmYYaIVVbwMsOojRrlKrRva7yctMGAcSDCcgbuu8lW5a7u2gpmhZb2fZJFv5wD/ PE5bAQrOqSEA+OGqBExqGW6DkNxAm7X96NyU8vdgnkVc+idlkOo9xGIbamlp8wpCRQ1I ySXNraZGBfLuPA58PTOqcpI1VIChLwM3IdVCV0nFLL4vYN+tiqm8nHF9/WY6OjvRCkHc flPIe/IIv5DFGFtmuUPZorp6Fw3+0OcVG+Yg0bMaNHF5dFUSb8kMu3npN5Ewx73p8LCq CqnA== X-Gm-Message-State: APjAAAXxBrsGqSk4OW1PsspPgaEbCxq1/jEylmEYuYcnL71Cti6J8CpW BkSOr4BmVmoHs+Hymgpd7IpqWYOkMpI= X-Google-Smtp-Source: APXvYqy2t64uvpm8RLDbiTH2OpkWwAEagDUms01DjKKGPh1uyIIO84hnnjp/IeafqLWANGwHlOFljw== X-Received: by 2002:a25:9a41:: with SMTP id r1mr295370ybo.295.1553120940137; Wed, 20 Mar 2019 15:29:00 -0700 (PDT) Received: from 42.do-not-panic.com (42.do-not-panic.com. [157.230.128.187]) by smtp.gmail.com with ESMTPSA id r19sm1108210ywg.70.2019.03.20.15.28.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Mar 2019 15:28:58 -0700 (PDT) Received: by 42.do-not-panic.com (sSMTP sendmail emulation); Wed, 20 Mar 2019 22:28:56 +0000 From: Luis Chamberlain To: akpm@linux-foundation.org, keescook@chromium.org Cc: sandeen@redhat.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Eric Sandeen , Luis Chamberlain Subject: [PATCH 5/6] test_sysctl: add proc_do_large_bitmap() test case Date: Wed, 20 Mar 2019 22:28:30 +0000 Message-Id: <20190320222831.8243-6-mcgrof@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190320222831.8243-1-mcgrof@kernel.org> References: <20190320222831.8243-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Sandeen The kernel has only two users of proc_do_large_bitmap(), the kernel CPU watchdog, and the ip_local_reserved_ports. Refer to watchdog_cpumask and ip_local_reserved_ports in Documentation for further details on these. When you input a large buffer into these, when it is larger than PAGE_SIZE - 1, the input data gets misparsed, and the user get incorrectly informed that the desired input value was set. This commit implements a test which mimics and exploits that use case, it uses a bitmap size, as in the watchdog case. The bitmap is used to test the bitmap proc handler, proc_do_large_bitmap(). The next commit fixes this issue. Signed-off-by: Eric Sandeen [mcgrof: use new target description for backward compatibility] [mcgrof: augment test number to 50, ran into issues with bash string comparisons when testing up to 50 cases.] [mcgrof: introduce and use verify_diff_proc_file() to use diff] [mcgrof: use mktemp for tmp file] [mcgrof: merge shell test and C code] [mcgrof: commit log love] [mcgrof: export proc_do_large_bitmap() to allow for the test [mcgrof: check for the return value when writing to the proc file] Signed-off-by: Luis Chamberlain --- kernel/sysctl.c | 1 + lib/test_sysctl.c | 18 +++++- tools/testing/selftests/sysctl/sysctl.sh | 81 +++++++++++++++++++++++- 3 files changed, 97 insertions(+), 3 deletions(-) diff --git a/kernel/sysctl.c b/kernel/sysctl.c index b3df3ab7ac28..e1a8d785b839 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -3263,6 +3263,7 @@ int proc_do_large_bitmap(struct ctl_table *table, int write, kfree(tmp_bitmap); return err; } +EXPORT_SYMBOL_GPL(proc_do_large_bitmap); #else /* CONFIG_PROC_SYSCTL */ diff --git a/lib/test_sysctl.c b/lib/test_sysctl.c index 3dd801c1c85b..566dad3f4196 100644 --- a/lib/test_sysctl.c +++ b/lib/test_sysctl.c @@ -47,6 +47,9 @@ struct test_sysctl_data { unsigned int uint_0001; char string_0001[65]; + +#define SYSCTL_TEST_BITMAP_SIZE 65536 + unsigned long *bitmap_0001; }; static struct test_sysctl_data test_data = { @@ -102,6 +105,13 @@ static struct ctl_table test_table[] = { .mode = 0644, .proc_handler = proc_dostring, }, + { + .procname = "bitmap_0001", + .data = &test_data.bitmap_0001, + .maxlen = SYSCTL_TEST_BITMAP_SIZE, + .mode = 0644, + .proc_handler = proc_do_large_bitmap, + }, { } }; @@ -129,15 +139,21 @@ static struct ctl_table_header *test_sysctl_header; static int __init test_sysctl_init(void) { + test_data.bitmap_0001 = kzalloc(SYSCTL_TEST_BITMAP_SIZE/8, GFP_KERNEL); + if (!test_data.bitmap_0001) + return -ENOMEM; test_sysctl_header = register_sysctl_table(test_sysctl_root_table); - if (!test_sysctl_header) + if (!test_sysctl_header) { + kfree(test_data.bitmap_0001); return -ENOMEM; + } return 0; } late_initcall(test_sysctl_init); static void __exit test_sysctl_exit(void) { + kfree(test_data.bitmap_0001); if (test_sysctl_header) unregister_sysctl_table(test_sysctl_header); } diff --git a/tools/testing/selftests/sysctl/sysctl.sh b/tools/testing/selftests/sysctl/sysctl.sh index 4eb019068e24..6a970b127c9b 100755 --- a/tools/testing/selftests/sysctl/sysctl.sh +++ b/tools/testing/selftests/sysctl/sysctl.sh @@ -38,6 +38,7 @@ ALL_TESTS="$ALL_TESTS 0002:1:1:string_0001" ALL_TESTS="$ALL_TESTS 0003:1:1:int_0002" ALL_TESTS="$ALL_TESTS 0004:1:1:uint_0001" ALL_TESTS="$ALL_TESTS 0005:3:1:int_0003" +ALL_TESTS="$ALL_TESTS 0006:50:1:bitmap_0001" test_modprobe() { @@ -150,6 +151,9 @@ reset_vals() string_0001) VAL="(none)" ;; + bitmap_0001) + VAL="" + ;; *) ;; esac @@ -180,6 +184,22 @@ verify() return 0 } +# proc files get read a page at a time, which can confuse diff, +# and get you incorrect results on proc files with long data. To use +# diff against them you must first extract the output to a file, and +# then compare against that file. +verify_diff_proc_file() +{ + TMP_DUMP_FILE=$(mktemp) + cat $1 > $TMP_DUMP_FILE + + if ! diff -w -q $TMP_DUMP_FILE $2; then + return 1 + else + return 0 + fi +} + verify_diff_w() { echo "$TEST_STR" | diff -q -w -u - $1 > /dev/null @@ -615,6 +635,55 @@ target_exists() return 1 } +run_bitmaptest() { + # Total length of bitmaps string to use, a bit under + # the maximum input size of the test node + LENGTH=$((RANDOM % 65000)) + + # First bit to set + BIT=$((RANDOM % 1024)) + + # String containing our list of bits to set + TEST_STR=$BIT + + # build up the string + while [ "${#TEST_STR}" -le "$LENGTH" ]; do + # Make sure next entry is discontiguous, + # skip ahead at least 2 + BIT=$((BIT + $((2 + RANDOM % 10)))) + + # Add new bit to the list + TEST_STR="${TEST_STR},${BIT}" + + # Randomly make it a range + if [ "$((RANDOM % 2))" -eq "1" ]; then + RANGE_END=$((BIT + $((1 + RANDOM % 10)))) + TEST_STR="${TEST_STR}-${RANGE_END}" + BIT=$RANGE_END + fi + done + + echo -n "Checking bitmap handler... " + TEST_FILE=$(mktemp) + echo -n "$TEST_STR" > $TEST_FILE + + cat $TEST_FILE > $TARGET 2> /dev/null + if [ $? -ne 0 ]; then + echo "FAIL" >&2 + rc=1 + test_rc + fi + + if ! verify_diff_proc_file "$TARGET" "$TEST_FILE"; then + echo "FAIL" >&2 + rc=1 + else + echo "ok" + rc=0 + fi + test_rc +} + sysctl_test_0001() { TARGET="${SYSCTL}/$(get_test_target 0001)" @@ -675,6 +744,14 @@ sysctl_test_0005() run_limit_digit_int_array } +sysctl_test_0006() +{ + TARGET="${SYSCTL}/bitmap_0001" + reset_vals + ORIG="" + run_bitmaptest +} + list_tests() { echo "Test ID list:" @@ -688,6 +765,7 @@ list_tests() echo "0003 x $(get_test_count 0003) - tests proc_dointvec()" echo "0004 x $(get_test_count 0004) - tests proc_douintvec()" echo "0005 x $(get_test_count 0005) - tests proc_douintvec() array" + echo "0006 x $(get_test_count 0006) - tests proc_do_large_bitmap()" } usage() @@ -761,8 +839,7 @@ function run_all_tests() ENABLED=$(get_test_enabled $TEST_ID) TEST_COUNT=$(get_test_count $TEST_ID) TEST_TARGET=$(get_test_target $TEST_ID) - target_exists $TEST_TARGET $TEST_ID - if [ $? -ne 1 ]; then + if target_exists $TEST_TARGET $TEST_ID; then continue fi if [[ $ENABLED -eq "1" ]]; then From patchwork Wed Mar 20 22:28:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 10862663 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 223DB1515 for ; Wed, 20 Mar 2019 22:29:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0255229E50 for ; Wed, 20 Mar 2019 22:29:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E443929ED8; Wed, 20 Mar 2019 22:29:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B262029E50 for ; Wed, 20 Mar 2019 22:29:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727757AbfCTW3G (ORCPT ); Wed, 20 Mar 2019 18:29:06 -0400 Received: from mail-yw1-f67.google.com ([209.85.161.67]:41487 "EHLO mail-yw1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727564AbfCTW3F (ORCPT ); Wed, 20 Mar 2019 18:29:05 -0400 Received: by mail-yw1-f67.google.com with SMTP id q128so3330609ywg.8; Wed, 20 Mar 2019 15:29:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DYaa3sSap9EzNyPtF8ZXKlbzOxq4cInzBuykp6Ou0k8=; b=D3cUyCL5f3Uq6Pwh6F8E7U4Y+laz4LNCpxp4+99ssEfXQITBwb1pFomrd1XEMlEyy4 eidjmU31Ses8TOzr40HRTfBLKp9Ozf2uAXoiOF/ZZa6k/j4HgahqF66J9QtQLxSQBX/E 6IguPBSvxmZyTIqrC1C/SREpHhsInaRzu7shmK8JUq21w+1LDZaNNYG0acsiDnMJ/DnE qMv/SHyWqWq/2z3of0Wbnqlkd4CDUccMxaoQwi7iw6OLfsNAPEACuwBZxg7GvWlTMJtF 2chj1Sx8M820E/3dbYGcJ8PvpK9T3tx4Onup20B/HVqPM3pcM2az2nZIndMVK3EQCwdJ tCbA== X-Gm-Message-State: APjAAAXyh4AxnmmLWOIWk+qKZ8tkUpIrYWTN4c3rxQy31Qm7bVIVnqYu 7hNmezsJf65SL2XW4ZRs6AA= X-Google-Smtp-Source: APXvYqxfpambTscKeen7xjavbFX57ULo+udBKXVmK3Us74m4heYIPhQWwo6aDaGNPVr52HGayqMZGQ== X-Received: by 2002:a5b:51:: with SMTP id e17mr386715ybp.64.1553120943931; Wed, 20 Mar 2019 15:29:03 -0700 (PDT) Received: from 42.do-not-panic.com (42.do-not-panic.com. [157.230.128.187]) by smtp.gmail.com with ESMTPSA id g1sm1052184ywf.0.2019.03.20.15.29.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Mar 2019 15:29:02 -0700 (PDT) Received: by 42.do-not-panic.com (sSMTP sendmail emulation); Wed, 20 Mar 2019 22:29:00 +0000 From: Luis Chamberlain To: akpm@linux-foundation.org, keescook@chromium.org Cc: sandeen@redhat.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Luis Chamberlain Subject: [PATCH 6/6] sysctl: Fix proc_do_large_bitmap for large input buffers Date: Wed, 20 Mar 2019 22:28:31 +0000 Message-Id: <20190320222831.8243-7-mcgrof@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190320222831.8243-1-mcgrof@kernel.org> References: <20190320222831.8243-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Sandeen Today, proc_do_large_bitmap() truncates a large write input buffer to PAGE_SIZE - 1, which may result in misparsed numbers at the (truncated) end of the buffer. Further, it fails to notify the caller that the buffer was truncated, so it doesn't get called iteratively to finish the entire input buffer. Tell the caller if there's more work to do by adding the skipped amount back to left/*lenp before returning. To fix the misparsing, reset the position if we have completely consumed a truncated buffer (or if just one char is left, which may be a "-" in a range), and ask the caller to come back for more. Signed-off-by: Eric Sandeen Acked-by: Kees Cook Signed-off-by: Luis Chamberlain --- kernel/sysctl.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/kernel/sysctl.c b/kernel/sysctl.c index e1a8d785b839..ddc6c717355d 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -3159,9 +3159,13 @@ int proc_do_large_bitmap(struct ctl_table *table, int write, if (write) { char *kbuf, *p; + size_t skipped = 0; - if (left > PAGE_SIZE - 1) + if (left > PAGE_SIZE - 1) { left = PAGE_SIZE - 1; + /* How much of the buffer we'll skip this pass */ + skipped = *lenp - left; + } p = kbuf = memdup_user_nul(buffer, left); if (IS_ERR(kbuf)) @@ -3178,9 +3182,22 @@ int proc_do_large_bitmap(struct ctl_table *table, int write, while (!err && left) { unsigned long val_a, val_b; bool neg; + size_t saved_left; + /* In case we stop parsing mid-number, we can reset */ + saved_left = left; err = proc_get_long(&p, &left, &val_a, &neg, tr_a, sizeof(tr_a), &c); + /* + * If we consumed the entirety of a truncated buffer or + * only one char is left (may be a "-"), then stop here, + * reset, & come back for more. + */ + if ((left <= 1) && skipped) { + left = saved_left; + break; + } + if (err) break; if (val_a >= bitmap_len || neg) { @@ -3198,6 +3215,15 @@ int proc_do_large_bitmap(struct ctl_table *table, int write, err = proc_get_long(&p, &left, &val_b, &neg, tr_b, sizeof(tr_b), &c); + /* + * If we consumed all of a truncated buffer or + * then stop here, reset, & come back for more. + */ + if (!left && skipped) { + left = saved_left; + break; + } + if (err) break; if (val_b >= bitmap_len || neg || @@ -3216,6 +3242,7 @@ int proc_do_large_bitmap(struct ctl_table *table, int write, proc_skip_char(&p, &left, '\n'); } kfree(kbuf); + left += skipped; } else { unsigned long bit_a, bit_b = 0;