Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp51302ybg; Tue, 9 Jun 2020 16:06:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/B0QLHno8tL9i0zqP97IDq1fFwkv8KMJf0DE2jHk7hP2yplbEXO19X+PrGO1LXEVwj5bJ X-Received: by 2002:a17:906:ca0e:: with SMTP id jt14mr602350ejb.325.1591743963149; Tue, 09 Jun 2020 16:06:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591743963; cv=none; d=google.com; s=arc-20160816; b=XxNQ0N0pKSZaw9KU1taP2f8U1EHPJLMZvlKnkOm2J9hve0WqKlcFl9jNVJr4lUQP3c vOTn5kKT319+DFhGPcZ2o9VPwRMOqrAVompKWcASQmgXA4X1GYwkhTsYyPRmNSHjKK/Y ompmc7pQSmznKc6AuHQh7Edzs2Yms+C2cj4+BpffOubkTxoq+CBsMszeDhZ3kPs2IzL6 snJx8tciHaJHi81w9aBD4rNOGnXgHD1oZoagur1VQksiPQEl4PBSQnv9rJTWmhxOxczH bFtna8QJB/WqCgt5OwEVZd9lq7TCi9QB+tKJBLui5g5sEIJMice+36uSSlKhwyXyfUtN 6FQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=sbyKrRW4jzkycRQ+AN5ObGaOSkiAmVbPRVaakkLPnrs=; b=BgtSQrdWkFpaC6v54cfjWrzsmXDg7SAlYsK8fAJhqvSn4WTf2n6AKVwqt777h/Xzg9 OmKLQSl6lEA5CHRauaDWHsS6kORm9tNLvanYxx+tcZo+droDv88OAw35LheOu6D1Zk1Z rMswqw8a2LXedsXJHwZ5qrtW1A7kg8riqKh7QOMPeA3XQg9tkuO1lQLZ0DfSXULlxHJx NYPP/TOzt67TGLhZdnMweEL2I951aaXxDtsLRXIvgzJ+Lt37w817aH7ZY/dn7R95gzzm yeEwm7ebW1RtryICMqpbg0uAmw3bNVqBAHv0SoM9yY+vLXu+H3ChU6Debil13Qpq02ks 944A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=RSCYouRT; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gr15si11436108ejb.214.2020.06.09.16.05.37; Tue, 09 Jun 2020 16:06:03 -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=@broadcom.com header.s=google header.b=RSCYouRT; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728915AbgFIW6s (ORCPT + 99 others); Tue, 9 Jun 2020 18:58:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728944AbgFIW5a (ORCPT ); Tue, 9 Jun 2020 18:57:30 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7A5CC008630 for ; Tue, 9 Jun 2020 15:57:22 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id b16so202336pfi.13 for ; Tue, 09 Jun 2020 15:57:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sbyKrRW4jzkycRQ+AN5ObGaOSkiAmVbPRVaakkLPnrs=; b=RSCYouRTVQme/oye/dD+eYbjykynXM6pZrpoJht84BG8sOQFmmktoX6n+nTmuRfWsZ zUTRaFbBUiRvdvZXWXuQhZTJtl5zjNpm2PP0xrn3UprLwSFPDQU+CGecbV73c9aDJC3A P+glRcPAT8mNOP3NA8BZjC03fKUSxb7iT5h30= 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; bh=sbyKrRW4jzkycRQ+AN5ObGaOSkiAmVbPRVaakkLPnrs=; b=nm54wISWYmgrYbSsbsw3pafqGYJ8RJhT5t3m/2mRY3vKbJaT2sD2OVul4hswKAMD9j eWwaymzHzbvu1bH374i/Whon+N4aL7ezvrHZA3zbzG8H4sOUUAJwbPeXgfVbHPgHIq/g zDSxxQSKNF97678Pmw1asQlLqqGp0ixZsWnaT7fW4ANjEWHBP6KPB0m7Ho8h0oQmRj1g aICyzIX8MTUi2t3o6sV09kk0qciUEJbQTTsEl1+GecbdObp+/Y+YZkGUDCesZqCWUj52 e6kluzxYbjQusHE6jb4dVHsFg68LF1aqGl2NpXeUE4yuly8wqb86KoD3Cxatjz7Ok2Kq uC3Q== X-Gm-Message-State: AOAM533wHX/kjcWTa1t7wOAOu8KGK0X3GHwWOEI6cTXq7Xmi6Cssw4Zq mLP/tZY8Md7ZQxLSVcewDtB0NQ== X-Received: by 2002:aa7:93b4:: with SMTP id x20mr97288pff.9.1591743441343; Tue, 09 Jun 2020 15:57:21 -0700 (PDT) Received: from lbrmn-lnxub113.broadcom.net ([192.19.228.250]) by smtp.gmail.com with ESMTPSA id p8sm9104978pgs.29.2020.06.09.15.57.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2020 15:57:20 -0700 (PDT) From: Scott Branden To: Luis Chamberlain , Wolfram Sang , Greg Kroah-Hartman , David Brown , Alexander Viro , Shuah Khan , bjorn.andersson@linaro.org, Shuah Khan , Arnd Bergmann Cc: Mimi Zohar , "Rafael J . Wysocki" , linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-fsdevel@vger.kernel.org, BCM Kernel Feedback , Olof Johansson , Andrew Morton , Dan Carpenter , Colin Ian King , Kees Cook , Takashi Iwai , linux-kselftest@vger.kernel.org, Andy Gross , linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, Scott Branden Subject: [PATCH v8 4/8] firmware: test partial file reads of request_firmware_into_buf Date: Tue, 9 Jun 2020 15:56:52 -0700 Message-Id: <20200609225656.18663-5-scott.branden@broadcom.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200609225656.18663-1-scott.branden@broadcom.com> References: <20200609225656.18663-1-scott.branden@broadcom.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add firmware tests for partial file reads of request_firmware_into_buf. Signed-off-by: Scott Branden --- .../selftests/firmware/fw_filesystem.sh | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/tools/testing/selftests/firmware/fw_filesystem.sh b/tools/testing/selftests/firmware/fw_filesystem.sh index fcc281373b4d..afc2e469ac06 100755 --- a/tools/testing/selftests/firmware/fw_filesystem.sh +++ b/tools/testing/selftests/firmware/fw_filesystem.sh @@ -149,6 +149,26 @@ config_unset_into_buf() echo 0 > $DIR/config_into_buf } +config_set_buf_size() +{ + echo $1 > $DIR/config_buf_size +} + +config_set_file_offset() +{ + echo $1 > $DIR/config_file_offset +} + +config_set_partial() +{ + echo 1 > $DIR/config_partial +} + +config_unset_partial() +{ + echo 0 > $DIR/config_partial +} + config_set_sync_direct() { echo 1 > $DIR/config_sync_direct @@ -207,6 +227,35 @@ read_firmwares() done } +read_partial_firmwares() +{ + if [ "$(cat $DIR/config_into_buf)" == "1" ]; then + fwfile="${FW_INTO_BUF}" + else + fwfile="${FW}" + fi + + if [ "$1" = "xzonly" ]; then + fwfile="${fwfile}-orig" + fi + + # Strip fwfile down to match partial offset and length + partial_data="$(cat $fwfile)" + partial_data="${partial_data:$2:$3}" + + for i in $(seq 0 3); do + config_set_read_fw_idx $i + + read_firmware="$(cat $DIR/read_firmware)" + + # Verify the contents are what we expect. + if [ $read_firmware != $partial_data ]; then + echo "request #$i: partial firmware was not loaded" >&2 + exit 1 + fi + done +} + read_firmwares_expect_nofile() { for i in $(seq 0 3); do @@ -319,6 +368,21 @@ test_batched_request_firmware_into_buf() echo "OK" } +test_batched_request_partial_firmware_into_buf() +{ + echo -n "Batched request_partial_firmware_into_buf() $2 off=$3 size=$4 try #$1: " + config_reset + config_set_name $TEST_FIRMWARE_INTO_BUF_FILENAME + config_set_into_buf + config_set_partial + config_set_buf_size $4 + config_set_file_offset $3 + config_trigger_sync + read_partial_firmwares $2 $3 $4 + release_all_firmware + echo "OK" +} + test_batched_request_firmware_direct() { echo -n "Batched request_firmware_direct() $2 try #$1: " @@ -371,6 +435,22 @@ for i in $(seq 1 5); do test_batched_request_firmware_into_buf $i normal done +for i in $(seq 1 5); do + test_batched_request_partial_firmware_into_buf $i normal 0 10 +done + +for i in $(seq 1 5); do + test_batched_request_partial_firmware_into_buf $i normal 0 5 +done + +for i in $(seq 1 5); do + test_batched_request_partial_firmware_into_buf $i normal 1 6 +done + +for i in $(seq 1 5); do + test_batched_request_partial_firmware_into_buf $i normal 2 10 +done + for i in $(seq 1 5); do test_batched_request_firmware_direct $i normal done -- 2.17.1