From patchwork Mon May 27 15:39:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13675534 X-Patchwork-Delegate: kuba@kernel.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2059.outbound.protection.outlook.com [40.107.7.59]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 291BE1640B; Mon, 27 May 2024 15:40:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.7.59 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716824422; cv=fail; b=kO5TjmZmiGqXvS8DwPxEDYS+oZlcoyKlohX5ylyItjAvFuMNjJ0ivj2fMt2rW5MMFPqecSvOcE8N2BfvTScssbXVB0Vc73+XliUeEkRJ6DWAEr6hf4D2RNgaCbLEhA4gkcvE7nZZ2RdadywVxqb0AJP7RMSYmUB9L+TzNH4sw2U= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716824422; c=relaxed/simple; bh=zhZfaShmwLFs/C8gLPXDvxVY21ttAXUQ8peaVE84q3U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=PL3hhmNkSQMC+Hx6Yu8Ve/rU8DJ5RcAiu5PzFmkrChCMxDsQUNLO3fyTYiV8oBOs1tyvzG5mzptGVxjltemdgbPgkzC2ndhBU/7mAds6J9Yw+6jfFR1tHzzoEHabU5nnDuz71WjWOiM3prlSZ7wuG4poZbDTyuB6Plj0keupO8Y= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b=Q1cxWoWu; arc=fail smtp.client-ip=40.107.7.59 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="Q1cxWoWu" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EgqkxW9wFa4rlmFjP4nLiaFjfVIyEBtCEx6Dd1KsiTlwQiq1FSUI+BJ3qmxaQ30LLGGFbfOAOl5PEHg+fMIqKxLzVf2V0vcL0sC/D3AIpierAfJ/NEpwCin9coSgO53YTHJJL+/Sa0TVyLWoqe48wp+f9hae/OLG+3W7vUiTg/aLIHMuT7R06b/qgWdmxX3eUaCdcXxHpuVhdK2Zu9yRiHyVK4Zm+1111y/XVk8BUiMQST7hKHN8p3UbGa48kmmsNt5EISMHBmaOq/la98ViDoABmUGvFoQfBeXg0ijYLEtbwao9NvUyIus63Jw9kE8+9+5OoNXqL/bmkIye6retMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=h7MVHDWb0SpZ5n3e6NWejnLCquP1pdFAYS5n8jnRT6o=; b=l28mfKDHpIICSwNfOqAE/gMEHOYdTRPThLefzsxsVVlZxcGYHqB6RR9E/5ASrQ46Zamt47mN+wBPwHTzP1kcVEY71yCBCZ0WGC0orel+D2Hhn0WVgQiq0znJBEu0OU9RzSzxShg716QqvBfpPcPIopvZd9++Bz7BKGaSGoqFjSobHKc/fdEGHj8Rjf/Q6u7gcEG0C1IG9Z5Hxwey2d8pUNA07x/qNtkKh4+uk9IYbKWjvx136o2V6HfSaS+ek9LPqCGpNfohny5n1xT9iBHmhFjWZ8GfuWtXbRPYIA6wPYNjUEiBNrafIieeSw7Ad+yOMh1Q2RwusKE59+1BHpkXPg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=h7MVHDWb0SpZ5n3e6NWejnLCquP1pdFAYS5n8jnRT6o=; b=Q1cxWoWu7CypwozwZZJeT4dgej6K8C3oE4qKExAF0UwE0u70yb7c80tfyyt/jcIStyJCHEZoqRD5gc0m3tNG8NmI2N3+YTA04wGQJKAppFusjSSztVEft3LMNVzOZEHVOgn+QgiuzHKlvRVWLNVANt5xK4x0rR/25glyYN6NT/I= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DB7PR04MB4555.eurprd04.prod.outlook.com (2603:10a6:5:33::26) by DB9PR04MB9961.eurprd04.prod.outlook.com (2603:10a6:10:4ee::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.29; Mon, 27 May 2024 15:40:15 +0000 Received: from DB7PR04MB4555.eurprd04.prod.outlook.com ([fe80::86ff:def:c14a:a72a]) by DB7PR04MB4555.eurprd04.prod.outlook.com ([fe80::86ff:def:c14a:a72a%7]) with mapi id 15.20.7611.025; Mon, 27 May 2024 15:40:15 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: linux-kselftest@vger.kernel.org, Vinicius Costa Gomes , Jamal Hadi Salim , Cong Wang , Jiri Pirko , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan , Pedro Tammela , syzbot+a7d2b1d5d1af83035567@syzkaller.appspotmail.com Subject: [PATCH net 2/2] net/sched: taprio: extend minimum interval restriction to entire cycle too Date: Mon, 27 May 2024 18:39:55 +0300 Message-Id: <20240527153955.553333-2-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240527153955.553333-1-vladimir.oltean@nxp.com> References: <20240527153955.553333-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: VI1PR06CA0116.eurprd06.prod.outlook.com (2603:10a6:803:8c::45) To DB7PR04MB4555.eurprd04.prod.outlook.com (2603:10a6:5:33::26) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB7PR04MB4555:EE_|DB9PR04MB9961:EE_ X-MS-Office365-Filtering-Correlation-Id: 29239629-6871-42cf-f9bd-08dc7e634dae X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|366007|1800799015|52116005|7416005|38350700005; X-Microsoft-Antispam-Message-Info: ZFGjM8/118U2ZJVdsKG7C53XbO62BkDyyg8i6Q3bryZE97YzxwmO8rF+O98W1C3LaCtO+7fZpzMHNR+023b7mHZMQJEJ0Zp2k1rdEkdraf794b4bUEX2Fl4fj5DWmP92yyIi3F9m+hgmVMgAKYsThpfO1QTqf6DNriRsCU0zuIPbmCSaji8GFH10mAUmERcCvsC9Zqi1nXVImxlLV7gympD7DjpW9wGbRUUa+GvfkGXeb+6haeZObq8sBOmGvC55acLD6QZgckSSzdf7eBGeZukPKi/cQK813fNqcwSLn1BZH/asP43kWm7IIkvgkjFqAGe06OWYsoLQjcSYpu5R8//Ge1UVfkP7PO3DHEhnliOtkD0wd0pHAFEFKEgjaBOwkOPYB0IxP42RQMwQvWXgPQlS0pZcj8iBDP0cn1dAdv2gjZaMtV1D4Dv3RX9yOWlOkXaJgvgs27UKhRLgM5IvDs4D7XvLUIUBnKhM1nDiMbcSkEpVohKZPhAIL9CARC4OYMVmjzliEWJXjhF3wVr5oJyd4OeMAFxavNv90gjlfOBlgtQn0+1S6lYzpPkk38yaPV5bmeIl89Pp+lHH7AIuN45RFOAbRhz/Wybe22UIcPz/TgVTGilC2hQJysPnUQyjli7czwx3ARgGSg75CcgRNNdYEtSoNinA20ifINeJn50bWoKMepatclkYBOV2sQxa0C5iPer35qlmXeZ0Usr8whidKyUI9dNMFW5xB/a2BijSBxlslCc2NRhySc3H01mYRA2o9QN9IhNxbx0CR3AsHd6DPbAKJUdIda7GEFXcY/85d4WnRZitENmyphv9EZ+sAp0xg0IxjGv9ia5AtGMdkS68jr53RP7Xvz56VARszrbq03P4y4nFpuE6O9zPqc+XqVfHGB+c8g4aB4eIt6MhzOU8yt8ljUIZgZlJjzHYTrIFo6wvmdyiP4idl1iOSQA6U9Zx9D9/vgAJDqsv5hF1sD8/jRadXqiqwNJ/uMU9kxvKc+kJmyvL7/TKdFNMFPAd2h4Ze39NXkT4dmn/3LYL+ucbYa+peZnXrxLdwec6ME/8vJu5qqsX6cnvDDKT8qwv/xLlGhohGEvEXr0zW+quXcYjNSyzMKZ44v7LCXVaVMhX1sNaxQC+qhBiOfhX6bEAxa4NJFuezR4Np8OCT18Gx1kFtpFhifc/SjVm6ny8ckY3UtkdK1GdWeQlW1okabfTIxMnnfYmu+kfONRbbKoM+IfD9/yT9qmRGEbmWJdFxUpP8wvP1XVUymHkWwXKx567TANZ2SaceovXgQUeOuRLVw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB7PR04MB4555.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376005)(366007)(1800799015)(52116005)(7416005)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2PpFBexIawHFxUzBz3vi1utcGY2MMSnEtIJUO7r3iUl6a57iY08PMSCFYDYQkk2+W6VSIF+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TelvqOQJ0cdbBlEXQKTP9PgSytPtlHCJQt5l2jOQRW1KsB750uPaiDFPtlOMDHGltApcloQHMTKBROBHOY4KGQxt1+Q29FgTp8zfX/nqo538ld6PpBi+bpLJLFwVhfg/I/us8YmxFP9YVmdCEIVZBz8iGrMq8yNSc6gXXbgDLe0TJN0hbK9brqFB0qL0K4l1Lkk9rn5Hf7k3OCWfGv1LAL/oPsv3O0+ruDSTlgLtv57oqzY2h3BV84uHstccmNyw+KKK9pZm4Fq2RCNLRqfkQSzEuv35cJr3ZVWNHv4RxBf1J3PlLk+mMYHtVOY7zicCCeEZ4A885xxxFBRZwqjwvLu0697vpoOzYXykrqPeMgnxQZ60m0gsN0oO5G3yCIia6P5cu+Dk9YPnC0yGrrhvHhtVhVIJ04CFdQUsDol3nQ0guL/evDq80Zc/y9cg4SFbHQXJZlwZXmNhQ== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 29239629-6871-42cf-f9bd-08dc7e634dae X-MS-Exchange-CrossTenant-AuthSource: DB7PR04MB4555.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2024 15:40:15.1331 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Z8znRZN03UL75sRLG54AQvi4ioUq9ctsl2+5bvzW16iRV2i5y3rZtUI4XPSDy+RmBa8wP45nj3mF6xg7mgklFg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9961 X-Patchwork-Delegate: kuba@kernel.org It is possible for syzbot to side-step the restriction imposed by the blamed commit in the Fixes: tag, because the taprio UAPI permits a cycle-time different from (and potentially shorter than) the sum of entry intervals. We need one more restriction, which is that the cycle time itself must be larger than N * ETH_ZLEN bit times, where N is the number of schedule entries. This restriction needs to apply regardless of whether the cycle time came from the user or was the implicit, auto-calculated value, so we move the existing "cycle == 0" check outside the "if "(!new->cycle_time)" branch. This way covers both conditions and scenarios. Add a selftest which illustrates the issue triggered by syzbot. Fixes: b5b73b26b3ca ("taprio: Fix allowing too small intervals") Reported-by: syzbot+a7d2b1d5d1af83035567@syzkaller.appspotmail.com Closes: https://lore.kernel.org/netdev/0000000000007d66bc06196e7c66@google.com/ Signed-off-by: Vladimir Oltean --- net/sched/sch_taprio.c | 10 ++++----- .../tc-testing/tc-tests/qdiscs/taprio.json | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c index 118915055360..937a0c513c17 100644 --- a/net/sched/sch_taprio.c +++ b/net/sched/sch_taprio.c @@ -1151,11 +1151,6 @@ static int parse_taprio_schedule(struct taprio_sched *q, struct nlattr **tb, list_for_each_entry(entry, &new->entries, list) cycle = ktime_add_ns(cycle, entry->interval); - if (!cycle) { - NL_SET_ERR_MSG(extack, "'cycle_time' can never be 0"); - return -EINVAL; - } - if (cycle < 0 || cycle > INT_MAX) { NL_SET_ERR_MSG(extack, "'cycle_time' is too big"); return -EINVAL; @@ -1164,6 +1159,11 @@ static int parse_taprio_schedule(struct taprio_sched *q, struct nlattr **tb, new->cycle_time = cycle; } + if (new->cycle_time < new->num_entries * length_to_duration(q, ETH_ZLEN)) { + NL_SET_ERR_MSG(extack, "'cycle_time' is too small"); + return -EINVAL; + } + taprio_calculate_gate_durations(q, new); return 0; diff --git a/tools/testing/selftests/tc-testing/tc-tests/qdiscs/taprio.json b/tools/testing/selftests/tc-testing/tc-tests/qdiscs/taprio.json index 8f12f00a4f57..557fb074acf0 100644 --- a/tools/testing/selftests/tc-testing/tc-tests/qdiscs/taprio.json +++ b/tools/testing/selftests/tc-testing/tc-tests/qdiscs/taprio.json @@ -154,6 +154,28 @@ "echo \"1\" > /sys/bus/netdevsim/del_device" ] }, + { + "id": "831f", + "name": "Add taprio Qdisc with too short cycle-time", + "category": [ + "qdisc", + "taprio" + ], + "plugins": { + "requires": "nsPlugin" + }, + "setup": [ + "echo \"1 1 8\" > /sys/bus/netdevsim/new_device" + ], + "cmdUnderTest": "$TC qdisc add dev $ETH root handle 1: taprio num_tc 2 queues 1@0 1@1 sched-entry S 01 200000 sched-entry S 02 200000 cycle-time 100 clockid CLOCK_TAI", + "expExitCode": "2", + "verifyCmd": "$TC qdisc show dev $ETH", + "matchPattern": "qdisc taprio 1: root refcnt", + "matchCount": "0", + "teardown": [ + "echo \"1\" > /sys/bus/netdevsim/del_device" + ] + }, { "id": "3e1e", "name": "Add taprio Qdisc with an invalid cycle-time",