Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1646363pxb; Thu, 4 Nov 2021 06:10:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzomq/CgZ0or2KvJ0Oqp2Ay+jfludnX6VeiZa/f5K7VOGezl6tUFToI0rDCQ/T+KSm5jg3u X-Received: by 2002:a05:6e02:1d02:: with SMTP id i2mr4708917ila.182.1636031435763; Thu, 04 Nov 2021 06:10:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1636031435; cv=none; d=google.com; s=arc-20160816; b=V6JZ9v5KOgzK05FjQ40FjaeOFknEwL1HZtr+7B1hJi9+DUxi2PTA5Zgv+k3RHU9pxl IUlYKpIYLH//IhYd18Lg8Gxk0CF6OTGkAvBTKAUljx1UzFy6T8j1IvQjW+rqc6Wdz6TK J86x62az3MCD4Tccg1ihoixo5pTgOgrhPbjVwRKAMbVrIOncZe4b6U8BEgMgRJk1PEBM +Kwy83HuD2iM8rEtd16SRmAgijr91h+GPbPZBaaEQxHQ8UpaUDuHc6kamYVngHQU0vTN Qo7YMvURtY3UyKi2Impf/4GPzIE7AHt0ncVEucwhsRZbVB107FwRkCpQYVMJchpXl4XY Qn7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=YI7bEsvaa9P6T1BxeXDJHD35omyehNZNvxDjHcofyQw=; b=OnvGTWuoH/rRSCsLMeuFvPSxiKwjjZZ+GYcKM5PBUjiTsxIifSFX38Db+FMNDnSV8L ELZdElH9Ha83l3aLlsmOg+SCYHk977P3L3KuHyHrD90AWn/0Q65JZejvPCl8GpbZmhsJ t9KBaUTyaHAYQT3eW2WpNiIfYM17MXE5wK4ixvrMcrPTKdaKuFLRR07Rse0deVdieA/i t3Hi9lKXi3FjXBC4ZT+66Ccu07W8qZrzziN+YxzvTSBPIXEVFlOQrk4FTXaFVrA4ON2w wzptzc2/VlLzZ6hXchZ3HqFRrzXngtWlledWdQ4LpbmoCWF0leFaf3N0vWddC3vdnEQN CyTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@waldekranz-com.20210112.gappssmtp.com header.s=20210112 header.b=KwUcpwdg; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h6si11670175iow.101.2021.11.04.06.10.10; Thu, 04 Nov 2021 06:10:35 -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=@waldekranz-com.20210112.gappssmtp.com header.s=20210112 header.b=KwUcpwdg; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231697AbhKDNJj (ORCPT + 99 others); Thu, 4 Nov 2021 09:09:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231217AbhKDNJi (ORCPT ); Thu, 4 Nov 2021 09:09:38 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2634EC06127A for ; Thu, 4 Nov 2021 06:07:00 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id s13so8568913wrb.3 for ; Thu, 04 Nov 2021 06:07:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=YI7bEsvaa9P6T1BxeXDJHD35omyehNZNvxDjHcofyQw=; b=KwUcpwdgzLUwVUY0mx23TgErTco3/7RgudpLX6qNtHIqZnEnQ2Xuy4ErChUaoHWZlR xed32y97cITsBTH6bQ19SQ4BgvzB2Nyp4HUGGJeMEapL/82gXWy5qI6pHHtOREZFeNr3 naAa4lNAmFH95Pt9HyqUkNGeAz1Fal+sZr8L+soMlJ0KdGBNVtG294YQgejE/hBhtxTh hxFbhFosyCo+BkpGj2BVOxHHfGb9EUG2bYNue+zYP6QMzZr7WctsVPxElRk2gJFjedJM RUE7pxQPcF3nCvoHfgbY+ot7nlFGaCU3cZfco6s1R+hguDmEUAuv6CZ4LfMhj3ECLPss tlNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=YI7bEsvaa9P6T1BxeXDJHD35omyehNZNvxDjHcofyQw=; b=mzDQakE7QayYXt2+jSaZoe+ARpDPM8X7FPKvBGr0RJshvKIPNjqk05iGPXtUUGC1Wj Nwf/ZINs5vWOaFnQ2pd2+pH41SWTeF3/sxvWH8O26/1rtPFf/t4BtDKi1+z6MEpWGxoz sp/mn7sjKpM+PgoXotrOpDEUlyQESxPJOHN6ZgBe87ufMldSdOUCN7dUV/BR6vVoQWX+ SRaYsgrKC0Q/fygcfhqqZ+YeKXzTjcNP3ffc4TvSkttgaLmbOc1Vmohpun7S8qKOnxjl dpLxQ6DhVsK59Hq3jxcPWsyXjWHVn38VaEFxnHTEaZCA2VuzQ9eoaHLpvo47xeMJXE8T FkPA== X-Gm-Message-State: AOAM5330SPGNH5F2UPB78IjxZoo0JY4ZMLNXn06XwIHi+h5lO5MNhQQv S6Ww7xxRLVM7YWU6a92kb8+gvQ== X-Received: by 2002:a05:6000:52:: with SMTP id k18mr51590433wrx.192.1636031218581; Thu, 04 Nov 2021 06:06:58 -0700 (PDT) Received: from wkz-x280 (static-193-12-47-89.cust.tele2.se. [193.12.47.89]) by smtp.gmail.com with ESMTPSA id c15sm4915251wrs.19.2021.11.04.06.06.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Nov 2021 06:06:58 -0700 (PDT) From: Tobias Waldekranz To: "Russell King (Oracle)" Cc: Andrew Lunn , Grygorii Strashko , "David S. Miller" , netdev@vger.kernel.org, Jakub Kicinski , Heiner Kallweit , Florian Fainelli , linux-kernel@vger.kernel.org, Vignesh Raghavendra , Sean Anderson Subject: Re: [RFC PATCH] net: phy/mdio: enable mmd indirect access through phy_mii_ioctl() In-Reply-To: References: <828e2d69-be15-fe69-48d8-9cfc29c4e76e@ti.com> <8d24c421-064c-9fee-577a-cbbf089cdf33@ti.com> <01a0ebf9-5d3f-e886-4072-acb9bf418b12@ti.com> <87pmrgjhk4.fsf@waldekranz.com> Date: Thu, 04 Nov 2021 14:06:54 +0100 Message-ID: <87k0hojci9.fsf@waldekranz.com> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 04, 2021 at 12:35, "Russell King (Oracle)" wrote: > On Thu, Nov 04, 2021 at 12:17:47PM +0100, Tobias Waldekranz wrote: >> On Wed, Nov 03, 2021 at 20:36, Andrew Lunn wrote: >> > On Wed, Nov 03, 2021 at 08:42:07PM +0200, Grygorii Strashko wrote: >> >> >> >> >> >> On 03/11/2021 02:27, Andrew Lunn wrote: >> >> > > > What i find interesting is that you and the other resent requester are >> >> > > > using the same user space tool. If you implement C45 over C22 in that >> >> > > > tool, you get your solution, and it will work for older kernels as >> >> > > > well. Also, given the diverse implementations of this IOTCL, it >> >> > > > probably works for more drivers than just those using phy_mii_ioctl(). >> >> > > >> >> > > Do you mean change uapi, like >> >> > > add mdio_phy_id_is_c45_over_c22() and >> >> > > flag #define MDIO_PHY_ID_C45_OVER_C22 0x4000? >> >> > >> >> > No, i mean user space implements C45 over C22. Make phytool write >> >> > MII_MMD_CTRL and MII_MMD_DATA to perform a C45 over C22. >> >> >> >> Now I give up - as mentioned there is now way to sync User space vs Kernel >> >> MMD transactions and so no way to get trusted results. >> >> Except that there is a way: https://github.com/wkz/mdio-tools > > I'm guessing that this hasn't had much in the way of review, as it has > a nice exploitable bug - you really want "pc" to be unsigned in > mdio_nl_eval(), otherwise one can write a branch instruction that makes > "pc" negative. You are quite right, it never got that far as it was NAKed on principle before that. I welcome the review, this is one of the reasons why I would love to have it in mainline. Alternatively, if someone has a better idea, I wouldn't mind adapting mdio-tools to whatever that interface would be. I agree that there should be much more rigorous checks around the modification of the PC. I will get on that. > Also it looks like one can easily exploit this to trigger any of your > BUG_ON()/BUG() statements, thereby crashing while holding the MDIO bus > lock causing a denial of service attack. The idea is that this is pre-validated in mdio_nl_validate_insn. Each instruction lists their acceptable argument types in mdio_nl_op_protos. > I also see nothing that protects against any user on a system being > able to use this interface, so the exploits above can be triggered by > any user. Moreover, this lack of protection means any user on the > system can use this interface to write to a PHY. I was under the impression that specifying GENL_ADMIN_PERM in the `struct genl_ops` would require the caller to hold CAP_NET_ADMIN? > Given that some PHYs today contain firmware, this gives anyone access > to reprogram the PHY firmware, possibly introducing malicious firmware. > > I hope no one is using this module in a production environment. Thanks for your review.