diff mbox series

[net] net/sched: taprio: always validate TCA_TAPRIO_ATTR_PRIOMAP

Message ID 20240604181511.769870-1-edumazet@google.com (mailing list archive)
State Accepted
Commit f921a58ae20852d188f70842431ce6519c4fdc36
Delegated to: Netdev Maintainers
Headers show
Series [net] net/sched: taprio: always validate TCA_TAPRIO_ATTR_PRIOMAP | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 900 this patch: 900
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 904 this patch: 904
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 904 this patch: 904
netdev/checkpatch warning WARNING: line length of 86 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-06-05--00-00 (tests: 1045)

Commit Message

Eric Dumazet June 4, 2024, 6:15 p.m. UTC
If one TCA_TAPRIO_ATTR_PRIOMAP attribute has been provided,
taprio_parse_mqprio_opt() must validate it, or userspace
can inject arbitrary data to the kernel, the second time
taprio_change() is called.

First call (with valid attributes) sets dev->num_tc
to a non zero value.

Second call (with arbitrary mqprio attributes)
returns early from taprio_parse_mqprio_opt()
and bad things can happen.

Fixes: a3d43c0d56f1 ("taprio: Add support adding an admin schedule")
Reported-by: Noam Rathaus <noamr@ssd-disclosure.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Vinicius Costa Gomes <vinicius.gomes@intel.com>
Cc: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 net/sched/sch_taprio.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

Comments

Vladimir Oltean June 4, 2024, 7:11 p.m. UTC | #1
On Tue, Jun 04, 2024 at 06:15:11PM +0000, Eric Dumazet wrote:
> If one TCA_TAPRIO_ATTR_PRIOMAP attribute has been provided,
> taprio_parse_mqprio_opt() must validate it, or userspace
> can inject arbitrary data to the kernel, the second time
> taprio_change() is called.
> 
> First call (with valid attributes) sets dev->num_tc
> to a non zero value.
> 
> Second call (with arbitrary mqprio attributes)
> returns early from taprio_parse_mqprio_opt()
> and bad things can happen.
> 
> Fixes: a3d43c0d56f1 ("taprio: Add support adding an admin schedule")
> Reported-by: Noam Rathaus <noamr@ssd-disclosure.com>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Vinicius Costa Gomes <vinicius.gomes@intel.com>
> Cc: Vladimir Oltean <vladimir.oltean@nxp.com>
> ---
>  net/sched/sch_taprio.c | 15 ++++++---------
>  1 file changed, 6 insertions(+), 9 deletions(-)
> 
> diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c
> index 937a0c513c17..b284a06b5a75 100644
> --- a/net/sched/sch_taprio.c
> +++ b/net/sched/sch_taprio.c
> @@ -1176,16 +1176,13 @@ static int taprio_parse_mqprio_opt(struct net_device *dev,
>  {
>  	bool allow_overlapping_txqs = TXTIME_ASSIST_IS_ENABLED(taprio_flags);
>  
> -	if (!qopt && !dev->num_tc) {
> -		NL_SET_ERR_MSG(extack, "'mqprio' configuration is necessary");
> -		return -EINVAL;
> -	}
> -
> -	/* If num_tc is already set, it means that the user already
> -	 * configured the mqprio part
> -	 */
> -	if (dev->num_tc)
> +	if (!qopt) {
> +		if (!dev->num_tc) {
> +			NL_SET_ERR_MSG(extack, "'mqprio' configuration is necessary");
> +			return -EINVAL;
> +		}
>  		return 0;
> +	}
>  
>  	/* taprio imposes that traffic classes map 1:n to tx queues */
>  	if (qopt->num_tc > dev->num_tx_queues) {
> -- 
> 2.45.2.505.gda0bf45e8d-goog
>

Correct, the mqprio qopt structure should be validated whenever passed,
not just if dev->num_tc == 0.

But... what bad things can happen?

Whenever I try to trick the kernel into doing something with the second
mqprio, I get:

"Changing the traffic mapping of a running schedule is not supported."
Vinicius Costa Gomes June 4, 2024, 9:12 p.m. UTC | #2
Eric Dumazet <edumazet@google.com> writes:

> If one TCA_TAPRIO_ATTR_PRIOMAP attribute has been provided,
> taprio_parse_mqprio_opt() must validate it, or userspace
> can inject arbitrary data to the kernel, the second time
> taprio_change() is called.
>
> First call (with valid attributes) sets dev->num_tc
> to a non zero value.
>
> Second call (with arbitrary mqprio attributes)
> returns early from taprio_parse_mqprio_opt()
> and bad things can happen.
>
> Fixes: a3d43c0d56f1 ("taprio: Add support adding an admin schedule")
> Reported-by: Noam Rathaus <noamr@ssd-disclosure.com>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Vinicius Costa Gomes <vinicius.gomes@intel.com>
> Cc: Vladimir Oltean <vladimir.oltean@nxp.com>
> ---
>  net/sched/sch_taprio.c | 15 ++++++---------
>  1 file changed, 6 insertions(+), 9 deletions(-)
>
> diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c
> index 937a0c513c17..b284a06b5a75 100644
> --- a/net/sched/sch_taprio.c
> +++ b/net/sched/sch_taprio.c
> @@ -1176,16 +1176,13 @@ static int taprio_parse_mqprio_opt(struct net_device *dev,
>  {
>  	bool allow_overlapping_txqs = TXTIME_ASSIST_IS_ENABLED(taprio_flags);
>  
> -	if (!qopt && !dev->num_tc) {
> -		NL_SET_ERR_MSG(extack, "'mqprio' configuration is necessary");
> -		return -EINVAL;
> -	}
> -
> -	/* If num_tc is already set, it means that the user already
> -	 * configured the mqprio part
> -	 */
> -	if (dev->num_tc)
> +	if (!qopt) {
> +		if (!dev->num_tc) {
> +			NL_SET_ERR_MSG(extack, "'mqprio' configuration is necessary");
> +			return -EINVAL;
> +		}
>  		return 0;
> +	}

Nice one. I think I have an idea of what's going on here.

Validating the priomap even if we are not going to install it is good:


Acked-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>


Cheers,
Vladimir Oltean June 4, 2024, 9:31 p.m. UTC | #3
On Tue, Jun 04, 2024 at 06:15:11PM +0000, Eric Dumazet wrote:
> If one TCA_TAPRIO_ATTR_PRIOMAP attribute has been provided,
> taprio_parse_mqprio_opt() must validate it, or userspace
> can inject arbitrary data to the kernel, the second time
> taprio_change() is called.
> 
> First call (with valid attributes) sets dev->num_tc
> to a non zero value.
> 
> Second call (with arbitrary mqprio attributes)
> returns early from taprio_parse_mqprio_opt()
> and bad things can happen.
> 
> Fixes: a3d43c0d56f1 ("taprio: Add support adding an admin schedule")
> Reported-by: Noam Rathaus <noamr@ssd-disclosure.com>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Vinicius Costa Gomes <vinicius.gomes@intel.com>
> Cc: Vladimir Oltean <vladimir.oltean@nxp.com>
> ---

Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
patchwork-bot+netdevbpf@kernel.org June 5, 2024, 11:10 p.m. UTC | #4
Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Tue,  4 Jun 2024 18:15:11 +0000 you wrote:
> If one TCA_TAPRIO_ATTR_PRIOMAP attribute has been provided,
> taprio_parse_mqprio_opt() must validate it, or userspace
> can inject arbitrary data to the kernel, the second time
> taprio_change() is called.
> 
> First call (with valid attributes) sets dev->num_tc
> to a non zero value.
> 
> [...]

Here is the summary with links:
  - [net] net/sched: taprio: always validate TCA_TAPRIO_ATTR_PRIOMAP
    https://git.kernel.org/netdev/net/c/f921a58ae208

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c
index 937a0c513c17..b284a06b5a75 100644
--- a/net/sched/sch_taprio.c
+++ b/net/sched/sch_taprio.c
@@ -1176,16 +1176,13 @@  static int taprio_parse_mqprio_opt(struct net_device *dev,
 {
 	bool allow_overlapping_txqs = TXTIME_ASSIST_IS_ENABLED(taprio_flags);
 
-	if (!qopt && !dev->num_tc) {
-		NL_SET_ERR_MSG(extack, "'mqprio' configuration is necessary");
-		return -EINVAL;
-	}
-
-	/* If num_tc is already set, it means that the user already
-	 * configured the mqprio part
-	 */
-	if (dev->num_tc)
+	if (!qopt) {
+		if (!dev->num_tc) {
+			NL_SET_ERR_MSG(extack, "'mqprio' configuration is necessary");
+			return -EINVAL;
+		}
 		return 0;
+	}
 
 	/* taprio imposes that traffic classes map 1:n to tx queues */
 	if (qopt->num_tc > dev->num_tx_queues) {