Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp13478163ybl; Sun, 29 Dec 2019 12:52:35 -0800 (PST) X-Google-Smtp-Source: APXvYqy/ZbifvkmW6lUySlr0hmdUO3vvbLFftluKlrWWYcV9Vf7hV+1yIViPUQHenOLpzaNYM93T X-Received: by 2002:a9d:7d99:: with SMTP id j25mr57017688otn.226.1577652755650; Sun, 29 Dec 2019 12:52:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577652755; cv=none; d=google.com; s=arc-20160816; b=YvELSl4U69O/1+oPyZS4WMzXgJywKPBDBm+fIcFX+COUUUen2wUOXnSI3iNizO/6+x ECB6+FhDdUYIAew/Q3r6trMZldDQUWqXWYSOc4m0bxiOzlkhP2jKncONJewPv85G9GLn wWwnWcWbjvl8Fqjot+zjvKLrZkYj81XwiKWGfrzv25UPE+QQjZljoZb5riRYPZt7zLg7 kcZgRx7C+RZjKFblmlXvkMdArt9dv3Znw7np2zb3S90jEQH1+1nFqRf/C/HeRgiXSYMG EqRF+pq6ii1PkXvIpb85I7LxMGzy9CNtYFI71ogl/wUY74g7ILLmB1ECSEI1CQr5UzLl P9Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NkXOFaESPUEmLxZFr21VRAetNcdWepjNGbvuPaYLaLI=; b=qm8tUXCfzRz6H27vw7+fwWnM7f4Lt/KqZeumHqr6AFh8uIeYsIh1fvirHLmVALEM89 RDTZfjIk0OluckQbIG4MlRLPbtMBaHGoUIOgQ2eILHymn/j6a0nPHqejDXu2tlcWm/Bz MT/eayzAfqheKBfRElGICgGc7ZgswSSBTVnZpRyflGGW3xBY8rQv1X6ZlgJICWU37zwT sn5tmu2Hecgcc5fQyzz3Rs1vyWmqPLDLIXMzEyG6F6zFnSajicDUos4a6g+VIwx6/rs3 VvkH+++sfL31yatRJs38RRXlluRrTcVOW6ROWUpAUhrzJhJzPq7o5Km/MoLR5IUJZp9J dCbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=addqcoWN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k131si15677955oia.64.2019.12.29.12.52.24; Sun, 29 Dec 2019 12:52:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=addqcoWN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387837AbfL2SRH (ORCPT + 99 others); Sun, 29 Dec 2019 13:17:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:41066 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727533AbfL2RX2 (ORCPT ); Sun, 29 Dec 2019 12:23:28 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BEA8E21744; Sun, 29 Dec 2019 17:23:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577640207; bh=SgAo8MiCmRcNxda/Wx+4lX2jC223OfII5kBxqJHI8Ak=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=addqcoWN2GXvX4LlLtzDjOZUML+uIWE04+/JvVlr1GWBGRrNRsOOJjNyi696xC7tG QIYg/iew+ARfPHAKyh0QDyQrkPGDPR9q4WyaW46lP2oxak+VIfK/XKMQp8nXL9iOHr pfhn65+iNTbkSLUuoIi/VmtkSLRFFF1H6rSW/FP0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ingo Rohloff , Sasha Levin Subject: [PATCH 4.14 062/161] usb: usbfs: Suppress problematic bind and unbind uevents. Date: Sun, 29 Dec 2019 18:18:30 +0100 Message-Id: <20191229162418.082916254@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191229162355.500086350@linuxfoundation.org> References: <20191229162355.500086350@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ingo Rohloff [ Upstream commit abb0b3d96a1f9407dd66831ae33985a386d4200d ] commit 1455cf8dbfd0 ("driver core: emit uevents when device is bound to a driver") added bind and unbind uevents when a driver is bound or unbound to a physical device. For USB devices which are handled via the generic usbfs layer (via libusb for example), this is problematic: Each time a user space program calls ioctl(usb_fd, USBDEVFS_CLAIMINTERFACE, &usb_intf_nr); and then later ioctl(usb_fd, USBDEVFS_RELEASEINTERFACE, &usb_intf_nr); The kernel will now produce a bind or unbind event, which does not really contain any useful information. This allows a user space program to run a DoS attack against programs which listen to uevents (in particular systemd/eudev/upowerd): A malicious user space program just has to call in a tight loop ioctl(usb_fd, USBDEVFS_CLAIMINTERFACE, &usb_intf_nr); ioctl(usb_fd, USBDEVFS_RELEASEINTERFACE, &usb_intf_nr); With this loop the malicious user space program floods the kernel and all programs listening to uevents with tons of bind and unbind events. This patch suppresses uevents for ioctls USBDEVFS_CLAIMINTERFACE and USBDEVFS_RELEASEINTERFACE. Signed-off-by: Ingo Rohloff Link: https://lore.kernel.org/r/20191011115518.2801-1-ingo.rohloff@lauterbach.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/core/devio.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c index 62b2a7105f02..4fb4cf8c2f14 100644 --- a/drivers/usb/core/devio.c +++ b/drivers/usb/core/devio.c @@ -755,8 +755,15 @@ static int claimintf(struct usb_dev_state *ps, unsigned int ifnum) intf = usb_ifnum_to_if(dev, ifnum); if (!intf) err = -ENOENT; - else + else { + unsigned int old_suppress; + + /* suppress uevents while claiming interface */ + old_suppress = dev_get_uevent_suppress(&intf->dev); + dev_set_uevent_suppress(&intf->dev, 1); err = usb_driver_claim_interface(&usbfs_driver, intf, ps); + dev_set_uevent_suppress(&intf->dev, old_suppress); + } if (err == 0) set_bit(ifnum, &ps->ifclaimed); return err; @@ -776,7 +783,13 @@ static int releaseintf(struct usb_dev_state *ps, unsigned int ifnum) if (!intf) err = -ENOENT; else if (test_and_clear_bit(ifnum, &ps->ifclaimed)) { + unsigned int old_suppress; + + /* suppress uevents while releasing interface */ + old_suppress = dev_get_uevent_suppress(&intf->dev); + dev_set_uevent_suppress(&intf->dev, 1); usb_driver_release_interface(&usbfs_driver, intf); + dev_set_uevent_suppress(&intf->dev, old_suppress); err = 0; } return err; -- 2.20.1