Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp265807rdb; Mon, 22 Jan 2024 21:05:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IEZInbV7ZlmjKqC69qSWzhk6Bo3UGlFcNLKHyzSpBaVrN7xjzbgv2ncBXIw393O451x4Kbt X-Received: by 2002:a05:6402:1244:b0:559:c471:7307 with SMTP id l4-20020a056402124400b00559c4717307mr541971edw.42.1705986351265; Mon, 22 Jan 2024 21:05:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705986351; cv=pass; d=google.com; s=arc-20160816; b=HHqmx0g78A3gAo6ipKEZx4XU0mu3c7CkaRGiSfFnKGER9d5E2T7VTP8UKbqFloMnro EVVX3cOF+KROuG6RMZI9Uvse68O1epzPnlzUxuJS4XHEE0dRuVD07o4X0ndMtR/n6ALb IxGRebMcJchic8VdzUjbLycB5ESXsjEofiv0o4TRD0QVbFkjwwkUJ4KV5DUhcdZ/mtFn zxxck8bXP6JVnBlNPrWLFnpVvUh1cCo+XYoEFaMlU9o8IOKLOR2UJ4jnI2Uh/eyL65yL MEaMdBuwmHwd+iehAs3MDg6ZMYDfDqW1+mg095cxbT1JgAS4i7qi/2SNNnIRyOWc7oCi dekw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=OBh6yiRTNxLOZ/bjMUM3HOUR4p9g7C916lKcuEsKw68=; fh=MUR88bFMIx3vFKp/j9Y9fWtpE04vvnu3U9YY6g14FHI=; b=YK+4NezJ7qPmNz/rThwPaCFeUFZXeG8Ug7oWEwkUAHP4kyQAVXtCrgC5Zp55tQ+NhR Y+0mzeMTaN0Y/JR5a4GULUfeQABeXrGiH9nyTWjHuTUXtnL3mN8ensEKtYDyvGRffqlz XZlBSDBIDUH80WiOIdnrs6Oyy4CmYyslRmJLRCr9N/NFwFnp0hMGaohbc9qJSy4b23GT kCBq/qg4veXVZ56Ue9oBSg2vgzky1i12OKUsH8Dfjty04jKfdp+68sqMbWYhjcNULfS9 be7gbeWnDiMv6kWjCCMFEdJ7aAKWA+suTrNOMv3HFqGbsYbfqvIoPjgwfhbgqNvvEjjy ToOQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=N7ZVuCqc; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-34716-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34716-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id fj15-20020a0564022b8f00b005581ef9ccdesi12242262edb.318.2024.01.22.21.05.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 21:05:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34716-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=N7ZVuCqc; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-34716-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34716-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 0A05F1F26728 for ; Tue, 23 Jan 2024 05:05:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 87FAC23AD; Tue, 23 Jan 2024 05:05:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="N7ZVuCqc" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 A752B1FBF; Tue, 23 Jan 2024 05:05:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705986337; cv=none; b=X6/jwShGcm6sTHxHyurheRSYhq+cAHc/+7z45LZ8V0V2Ph1z2OkBBdi9fCF/iwE2CzJ2PkQQ+mQzQYvGn9fjCrhWsGR+MRR7B6lmUBRTelZzRV0kEPXrDD5F1FeWpwkJk5SBZhaOKcX1OA1YmKzuv5YWD5b7i3qcPkrd5upm9qU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705986337; c=relaxed/simple; bh=//WOM0oQR5MlLwRUy+ZM05+864HU5PzrMPj0MibHAsI=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=K47eRArN5WaJNpmDJzi0HJqfUO1/p6V6xblKDTg5r4yI+81qaMdk6rS1gXmT00qtntBHtRvj/Ceo/Ucsl0SkqWN6vTnbiMx8BRq6Dg3opQepbxOfI5l0cl9F8VK8asg/dnveXIcWoJYYxc2WL2a1aNPVH1UnVa4zPqryKh/+9ns= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=N7ZVuCqc; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id ECAEAC433F1; Tue, 23 Jan 2024 05:05:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705986337; bh=//WOM0oQR5MlLwRUy+ZM05+864HU5PzrMPj0MibHAsI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=N7ZVuCqcgB1Y7LeCxTjnJKx2V7GCJrIDuFuICLYPSpTD8BRPfhARXe1e9q6DahI4R L5/qMIkl+bAbGcfCxZEuflaVazBzK7yv4hA5PSjBb+mRAO1TUd0z0zPuZ5dytPN3Za SDeoaZUjYtQdT7D37f5z8KxBzKHG97r8zJTw1KFQKZav0X1N5M26XyFP3lNh7Uy7+v kzHr0RzZ/bqB8EtM1xc7wlwI3oMc8s4M4nHkRtfoEhIEbSkzI6te1QDmdcQ7rJhRhx zep7yHCJoDdYF9wHwIn3lsD/nV0IqRKheq9swUXje2m68/zgEMiSmEXYyXz2W37yzR 8KOz78uPyzsmw== Date: Mon, 22 Jan 2024 21:05:34 -0800 From: Jakub Kicinski To: Danielle Ratson Cc: , , , , , , , , , , , , , , , , , , , , Subject: Re: [RFC PATCH net-next 9/9] ethtool: Add ability to flash transceiver modules' firmware Message-ID: <20240122210534.5054b202@kernel.org> In-Reply-To: <20240122084530.32451-10-danieller@nvidia.com> References: <20240122084530.32451-1-danieller@nvidia.com> <20240122084530.32451-10-danieller@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 22 Jan 2024 10:45:30 +0200 Danielle Ratson wrote: > #include > +#include > +#include alphabetical order, please > +static int > +module_flash_fw_schedule(struct net_device *dev, > + struct ethtool_module_fw_flash_params *params, > + struct netlink_ext_ack *extack) > +{ > + const struct ethtool_ops *ops = dev->ethtool_ops; > + struct ethtool_module_fw_flash *module_fw; > + int err; > + > + if (!ops->set_module_eeprom_by_page || > + !ops->get_module_eeprom_by_page) { > + NL_SET_ERR_MSG(extack, > + "Flashing module firmware is not supported by this device"); > + return -EOPNOTSUPP; > + } > + > + if (dev->module_fw_flash_in_progress) { > + NL_SET_ERR_MSG(extack, "Module firmware flashing already in progress"); > + return -EBUSY; > + } > + > + module_fw = kzalloc(sizeof(*module_fw), GFP_KERNEL); > + if (!module_fw) > + return -ENOMEM; > + > + module_fw->params = *params; > + err = request_firmware(&module_fw->fw, module_fw->params.file_name, request_firmware_direct() ? I think udev timeout is 30 sec and we're holding rtnl_lock.. I don't remember why we didn't use that in devlink > + &dev->dev); > + if (err) { > + NL_SET_ERR_MSG(extack, > + "Failed to request module firmware image"); > + goto err_request_firmware; > + } > + > + err = module_flash_fw_work_init(module_fw, dev, extack); > + if (err < 0) { > + NL_SET_ERR_MSG(extack, > + "Flashing module firmware is not supported by this device"); > + goto err_work_init; > + } > + > + dev->module_fw_flash_in_progress = true; What does this protect us from? > +static int module_flash_fw(struct net_device *dev, struct nlattr **tb, > + struct netlink_ext_ack *extack) > +{ > + struct ethtool_module_fw_flash_params params = {}; > + struct nlattr *attr; > + > + if (!tb[ETHTOOL_A_MODULE_FW_FLASH_FILE_NAME]) { > + NL_SET_ERR_MSG_ATTR(extack, GENL_REQ_ATTR_CHECK, and you can check it in the caller, before taking rtnl_lock. > + tb[ETHTOOL_A_MODULE_FW_FLASH_FILE_NAME], > + "File name attribute is missing"); > + return -EINVAL; > + } > + > + params.file_name = > + nla_data(tb[ETHTOOL_A_MODULE_FW_FLASH_FILE_NAME]); Hm. I think you copy the param struct by value to the work container. nla_data() is in the skb which is going to get freed after _ACT returns. So if anyone tries to access the name from the work it's going to UAF? > + > + attr = tb[ETHTOOL_A_MODULE_FW_FLASH_PASSWORD]; > + if (attr) { > + params.password = cpu_to_be32(nla_get_u32(attr)); > + params.password_valid = true; > + } > + > + return module_flash_fw_schedule(dev, ¶ms, extack); > +}