Received: by 2002:a05:6500:1b41:b0:1fb:d597:ff75 with SMTP id cz1csp271711lqb; Tue, 4 Jun 2024 10:47:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWjnVxqFVZUfXjdmK2KDYa5EaQ4o3xNE/htE2Xco2VNXz8TZKHREmNNCEmdf6edLsE7eJkz63CbzOs8vssJBH816RLUWe25VRgJySEqBA== X-Google-Smtp-Source: AGHT+IFOMMILHwVnvn7KxBhb765QZIi4Vl6hfzQse67KDrftCVdUft7sUW0/GUGl4HvtKdQO8OS/ X-Received: by 2002:a17:906:c250:b0:a68:bb1b:4de0 with SMTP id a640c23a62f3a-a699f363631mr19429066b.7.1717523279714; Tue, 04 Jun 2024 10:47:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717523279; cv=pass; d=google.com; s=arc-20160816; b=KpgY4eWVkJxVPITgugI7n05TXNDe+3PgGIGIbU3TGrM4HO9a4eAxY7X9dNZA8oxBp6 qGv0NgpHL7bLgoyo9syuLUyyz175VWVxij8c95hlQnA1LV8enOxGrxcNGO9WVAQnZn+6 EeaihlxUT4eDkVxQvJ87kUJt2FbRPOv2d+WKkd68+jpyKnet7COUpLwKFWfGKqJybhIW rMdDTGUFSH79kXDR53+W6r8Z3jul/IfGfUjQvviQ38TOJrz0sZ1aH26pHVkhcWy05mmI U3v0Tn65RgIQQUKkx8T+ww1ZjrK4/n9g0gtQwDxXc9RD37LWF+kaFdfK4VuJDl3np9cB 8U0g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=8XbnqD4n6koiFQjgfJFBGUzksR7WWJ5UeKSAWi5AcXc=; fh=fqoQn1vxgQ/bZ7Ua2J8zr03y2Gz5il5xXZvXvGsTsl8=; b=mxWBSAuxrAJXkyhfHAmBvNzpuTELn69jplTcKLQj5ivKEmtuCSvr1ghnWRC75PMYvx 6ra8UX8ptDOV57QQ+JNmXxb4boqNXwqc9egbhDthpBtFWO4cSw1RGdO57WB1TugNOUKA fnQs+W3T24ggJwpzMp3vutfq/k0lFSoVPwsCYq7ks4QEz2BGDplOienmyZevTgPCDpW6 Wa6V4lO0257Q9XzwjiW2oyPFVZgqtu1sKCsLlt0eA6kVAOz+DLIeGaj8KCn2jDgMs4Xr B/45l8Pub0YXnEClUXMK3CHpxp2eKe22OfBzOSkgthmlbkk8E35EONuM3fZJf1TiiOjA 1f4g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=netrider.rowland.org); spf=pass (google.com: domain of linux-kernel+bounces-201203-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201203-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=harvard.edu Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a6912c5c917si195773366b.808.2024.06.04.10.47.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 10:47:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-201203-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=netrider.rowland.org); spf=pass (google.com: domain of linux-kernel+bounces-201203-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201203-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=harvard.edu 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 00F671F215BB for ; Tue, 4 Jun 2024 17:47:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4A3D314B965; Tue, 4 Jun 2024 17:45:21 +0000 (UTC) Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by smtp.subspace.kernel.org (Postfix) with SMTP id 294C214B09E for ; Tue, 4 Jun 2024 17:45:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.131.102.5 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717523120; cv=none; b=MjmVlhCF4pqlFNPM3HCeI+sSkWrobN9Cp2n04Eq7h+86C1BEg6XMWu85skWAWp61lQgAL0hkc/zH1Kh6XliaKr6os8cbXdOJJ/0Ww5J3irjQ+dTV2ufMuzs4XnnoTzCv4C0XZaeQ1oHEFaH4ILMOyikNxG0KCRdodTisgHIiGwg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717523120; c=relaxed/simple; bh=Ddf0qc15ARD9S0pv1k9Mm0ZFp3pL46h9tOnJ56TQick=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PwySSLEwaaY4bKK0sW/WrLlD9wdCyCirLrL2gzB5HweSQsicxolQdUM8O4x0/W68eY1T8CrWG6XJ4fdmQ/MLN7gmZYE21T8bYasvEzht05RihShl3Fd036tzMkWjuRn9il7rUqM2jWXHnykcRTR7Uj7fiPUn/6GrBv7CBcFlZn4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=rowland.harvard.edu; spf=pass smtp.mailfrom=netrider.rowland.org; arc=none smtp.client-ip=192.131.102.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=rowland.harvard.edu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=netrider.rowland.org Received: (qmail 165513 invoked by uid 1000); 4 Jun 2024 13:45:18 -0400 Date: Tue, 4 Jun 2024 13:45:18 -0400 From: Alan Stern To: Kees Cook Cc: Nikita Zhandarovich , Jiri Kosina , Benjamin Tissoires , linux-usb@vger.kernel.org, linux-input@vger.kernel.org, syzkaller-bugs@googlegroups.com, linux-kernel@vger.kernel.org, syzbot+c52569baf0c843f35495@syzkaller.appspotmail.com, linux-hardening@vger.kernel.org Subject: Re: [PATCH] HID: usbhid: fix recurrent out-of-bounds bug in usbhid_parse() Message-ID: References: <20240524120112.28076-1-n.zhandarovich@fintech.ru> <2a38e355-af5c-4b3d-81be-0cc97376c1f5@fintech.ru> <202406041019.BCD0A93C@keescook> 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-Disposition: inline In-Reply-To: <202406041019.BCD0A93C@keescook> On Tue, Jun 04, 2024 at 10:21:15AM -0700, Kees Cook wrote: > On Tue, Jun 04, 2024 at 10:09:43AM -0700, Nikita Zhandarovich wrote: > > Hi, > > > > On 6/4/24 07:15, Jiri Kosina wrote: > > > On Tue, 4 Jun 2024, Kees Cook wrote: > > > > > >> This isn't the right solution. The problem is that hid_class_descriptor > > >> is a flexible array but was sized as a single element fake flexible > > >> array: > > >> > > >> struct hid_descriptor { > > >> __u8 bLength; > > >> __u8 bDescriptorType; > > >> __le16 bcdHID; > > >> __u8 bCountryCode; > > >> __u8 bNumDescriptors; > > >> > > >> struct hid_class_descriptor desc[1]; > > >> } __attribute__ ((packed)); > > >> > > >> This likely needs to be: > > >> > > >> struct hid_class_descriptor desc[] __counted_by(bNumDescriptors); > > >> > > >> And then check for any sizeof() uses of the struct that might have changed. > > > > > > Ah, you are of course right, not sure what I was thinking. Thanks a lot > > > for catching my brainfart. > > > > > > I am dropping the patch for now; Nikita, will you please send a refreshed > > > one? > > > > > > > Thanks for catching my mistake. > > > > I'll gladly send a revised version, hoping to do it very soon. > > I spent a little more time looking at this, and I'm not sure I > understand where the actual space for the descriptors comes from? > There's interface->extra that is being parsed, and effectively > hid_descriptor is being mapped into it, but it uses "sizeof(struct > hid_descriptor)" for the limit. That's a lower limit, not an upper limit. The hid_descriptor must include at least one hid_class_descriptor, but it can include more. That's what the min_t() calculation of num_descriptors is meant to figure out. > Is more than 1 descriptor expected to > work correctly? More than one hid_class_descriptor -- yes. > Or is the limit being ignored? I'm a bit confused by > this code... Does this explain it? Alan Stern