Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2831949pxv; Mon, 12 Jul 2021 03:03:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyyRL6n+95eFvfGupGxZVl2mnwTdmj9u27xf+2QXgfbJ2YrCBq7yU71hZbNrXciNYp0Ijiz X-Received: by 2002:aa7:c952:: with SMTP id h18mr62664231edt.18.1626084187105; Mon, 12 Jul 2021 03:03:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626084187; cv=none; d=google.com; s=arc-20160816; b=zmjtfPgO/FZrS2K2FF7H0wz5foXgl5MlkqoFjBHGCUsP110dYTYSNHsuGSBZbThlOk fYa8wUx/P3zLmE1tOExEnSXcqfKy/9fJx2SEPEFwg6RiZT3k49Ujd6jqa6/78Vxj7Aja xEn9wGguu1ZFjZCweWylnyduulLMsN7qOg87sFEfElWZzCqCs7L0CRRCmIcAtbVw7mzx onJqjA4x3jORq/zlcNLwDz2gPIbgAQUZxrZ61s5mequ206V9fKbHpJvl0WuAF2DB19aM +dipoh48QfiW/+6iR/vRa0vX+cePqQV6NfAutdRQfSyXS74zsOSmAzKc6Q6tNjoSmmdh 0gZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZAESFXVkbnsGD5q4b3TD3U5jVYZY91CdBtSu8YOy998=; b=ibxH5fOArpLtlZ58r1Wg5BdQBmBgW2qx+nqO9rTHn83DPYh/DXE7kTFPPkQJcbrBAj B3zJzXEWLOKA0jzmch/+zSMGuw1a3NtUHiSzIBonT3h8e5S1D5E4cOHEBHBbi0qVLbDS Z9yvbnjUfifiCrFlI+nL+cl50KFqm2+i13Z9ojMqARrVqLk9W+E3Dbq4TVbpwKEdLDgA tNEF/P5BG35DbEoTScpJ8Vy4EaQyoBXutOGRsQSoou1Y+BdcVWMDsjBxyZSAJYE3XAIn wkON+vPUM5Xd8jNc+PuFNv81Dpvb8feTzOnJliFcePgEXG+PygZLgjJAFBcUHcEkMnQ/ WUBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BQRXBj3F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k5si13881320edx.484.2021.07.12.03.02.44; Mon, 12 Jul 2021 03:03:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BQRXBj3F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244363AbhGLHRb (ORCPT + 99 others); Mon, 12 Jul 2021 03:17:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:49944 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240000AbhGLGub (ORCPT ); Mon, 12 Jul 2021 02:50:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 31C3E60233; Mon, 12 Jul 2021 06:47:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626072444; bh=DUgcB785XMcpeEq5Yt6WrbqQKAkHFMhqCwGsYbSv/5w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BQRXBj3FTYXNydEAHs68LElIsLjrHSvPXUPXm496EB3gRTCibYAjCOciOUNIK7FDJ ICwlQ9g5wKtjGYTYj4JGpO+j5I6NRnFY08w9C/rNaqmcKxCBjwq1b6U6yKL3izz10b 68YdZDGly74u9/v3hhNXdKhORhqBlgImmh+g07DI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, kernel test robot , Christoph Hellwig , Shuah Khan , linux-kselftest@vger.kernel.org, Kees Cook , Shuah Khan , Sasha Levin Subject: [PATCH 5.10 499/593] selftests: splice: Adjust for handler fallback removal Date: Mon, 12 Jul 2021 08:10:59 +0200 Message-Id: <20210712060946.416271738@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060843.180606720@linuxfoundation.org> References: <20210712060843.180606720@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kees Cook [ Upstream commit 6daf076b717d189f4d02a303d45edd5732341ec1 ] Some pseudo-filesystems do not have an explicit splice fops since adding commit 36e2c7421f02 ("fs: don't allow splice read/write without explicit ops"), and now will reject attempts to use splice() in those filesystem paths. Reported-by: kernel test robot Link: https://lore.kernel.org/lkml/202009181443.C2179FB@keescook/ Fixes: 36e2c7421f02 ("fs: don't allow splice read/write without explicit ops") Cc: Christoph Hellwig Cc: Shuah Khan Cc: linux-kselftest@vger.kernel.org Signed-off-by: Kees Cook Signed-off-by: Shuah Khan Signed-off-by: Sasha Levin --- .../selftests/splice/short_splice_read.sh | 119 ++++++++++++++---- 1 file changed, 98 insertions(+), 21 deletions(-) diff --git a/tools/testing/selftests/splice/short_splice_read.sh b/tools/testing/selftests/splice/short_splice_read.sh index 7810d3589d9a..22b6c8910b18 100755 --- a/tools/testing/selftests/splice/short_splice_read.sh +++ b/tools/testing/selftests/splice/short_splice_read.sh @@ -1,21 +1,87 @@ #!/bin/sh # SPDX-License-Identifier: GPL-2.0 +# +# Test for mishandling of splice() on pseudofilesystems, which should catch +# bugs like 11990a5bd7e5 ("module: Correctly truncate sysfs sections output") +# +# Since splice fallback was removed as part of the set_fs() rework, many of these +# tests expect to fail now. See https://lore.kernel.org/lkml/202009181443.C2179FB@keescook/ set -e +DIR=$(dirname "$0") + ret=0 +expect_success() +{ + title="$1" + shift + + echo "" >&2 + echo "$title ..." >&2 + + set +e + "$@" + rc=$? + set -e + + case "$rc" in + 0) + echo "ok: $title succeeded" >&2 + ;; + 1) + echo "FAIL: $title should work" >&2 + ret=$(( ret + 1 )) + ;; + *) + echo "FAIL: something else went wrong" >&2 + ret=$(( ret + 1 )) + ;; + esac +} + +expect_failure() +{ + title="$1" + shift + + echo "" >&2 + echo "$title ..." >&2 + + set +e + "$@" + rc=$? + set -e + + case "$rc" in + 0) + echo "FAIL: $title unexpectedly worked" >&2 + ret=$(( ret + 1 )) + ;; + 1) + echo "ok: $title correctly failed" >&2 + ;; + *) + echo "FAIL: something else went wrong" >&2 + ret=$(( ret + 1 )) + ;; + esac +} + do_splice() { filename="$1" bytes="$2" expected="$3" + report="$4" - out=$(./splice_read "$filename" "$bytes" | cat) + out=$("$DIR"/splice_read "$filename" "$bytes" | cat) if [ "$out" = "$expected" ] ; then - echo "ok: $filename $bytes" + echo " matched $report" >&2 + return 0 else - echo "FAIL: $filename $bytes" - ret=1 + echo " no match: '$out' vs $report" >&2 + return 1 fi } @@ -23,34 +89,45 @@ test_splice() { filename="$1" + echo " checking $filename ..." >&2 + full=$(cat "$filename") + rc=$? + if [ $rc -ne 0 ] ; then + return 2 + fi + two=$(echo "$full" | grep -m1 . | cut -c-2) # Make sure full splice has the same contents as a standard read. - do_splice "$filename" 4096 "$full" + echo " splicing 4096 bytes ..." >&2 + if ! do_splice "$filename" 4096 "$full" "full read" ; then + return 1 + fi # Make sure a partial splice see the first two characters. - do_splice "$filename" 2 "$two" + echo " splicing 2 bytes ..." >&2 + if ! do_splice "$filename" 2 "$two" "'$two'" ; then + return 1 + fi + + return 0 } -# proc_single_open(), seq_read() -test_splice /proc/$$/limits -# special open, seq_read() -test_splice /proc/$$/comm +### /proc/$pid/ has no splice interface; these should all fail. +expect_failure "proc_single_open(), seq_read() splice" test_splice /proc/$$/limits +expect_failure "special open(), seq_read() splice" test_splice /proc/$$/comm -# proc_handler, proc_dointvec_minmax -test_splice /proc/sys/fs/nr_open -# proc_handler, proc_dostring -test_splice /proc/sys/kernel/modprobe -# proc_handler, special read -test_splice /proc/sys/kernel/version +### /proc/sys/ has a splice interface; these should all succeed. +expect_success "proc_handler: proc_dointvec_minmax() splice" test_splice /proc/sys/fs/nr_open +expect_success "proc_handler: proc_dostring() splice" test_splice /proc/sys/kernel/modprobe +expect_success "proc_handler: special read splice" test_splice /proc/sys/kernel/version +### /sys/ has no splice interface; these should all fail. if ! [ -d /sys/module/test_module/sections ] ; then - modprobe test_module + expect_success "test_module kernel module load" modprobe test_module fi -# kernfs, attr -test_splice /sys/module/test_module/coresize -# kernfs, binattr -test_splice /sys/module/test_module/sections/.init.text +expect_failure "kernfs attr splice" test_splice /sys/module/test_module/coresize +expect_failure "kernfs binattr splice" test_splice /sys/module/test_module/sections/.init.text exit $ret -- 2.30.2