Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4232076imm; Tue, 25 Sep 2018 13:44:38 -0700 (PDT) X-Google-Smtp-Source: ACcGV62oG/jtpIzdLBdqQ0zf8IfZfd+FpeY1I8mwfwZd/NJAjRHvvRgMYso5x27Pr6AahiMk2+H9 X-Received: by 2002:a63:574c:: with SMTP id h12-v6mr2569119pgm.423.1537908278124; Tue, 25 Sep 2018 13:44:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537908278; cv=none; d=google.com; s=arc-20160816; b=NlkXVzfvFmDdvwbWCL8Kn7+vXFjYUNcSTwm3vvoKh+J1GhqywKzTyOszqII68I3wA0 gOxrxb5V3AXDsywFMN0xc1wliS56lFsq7J3Y2C9ysUacag6GEJ6JEoYwtoDLpfuMD0GD 55kqfTojhoySbIJVRlTyKOHfWBSMJrDdE3Cd2Usebp++YtyGhw3vbtTRJtxYoP1CHY5O gXBkMbrjlHNWy1JoiCkryn83zuh4XhH/aAzugUkbYRIfDteuBBwxGBX9HboTMdk92fio NrfVn8mLA9baPFUDaQuMQLT5QeBgLwJ1OFHIjiFiDjjqKUfP+Jv4z4UwwsZFfndX3JEh TsBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to :subject:cc:to:from:date; bh=frMzs7gmdZ0P+kAIv+XfGrSiC0cDfim+jnEjcEgxKho=; b=YeBS5AhrpfmS1Fk5kjMU0OWGhc4AC7R+Lr7x1CKsBL3Zw16ThyP4d794Fk200dXV4R L+a8EWjSeX7cFrzz0o04qcPtLb109k56ViIT4oM1AJCls0imRicXBy2+yQlc/isbZXLB Etx5H3MjSBffFvHjT6f9JWQSO8QQUWvHSuc1U34sHXT7sSLEo1kF4rXLKPhPwxTP4UIc ARIIgCVBBqZjEC4O0BeN/qW8V5VKqeYymQte4C0YTvVBKCwcxnAVBBqcYZFuNUDYx58A e/ZZdiMcthwpgFkR2Ol3THBuFue6h4qxXtIJ86TqM7ZEY4nZWDKtH0XeEHPrmaL1ZVqB LaaA== ARC-Authentication-Results: i=1; mx.google.com; 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 s6-v6si3348555pfd.59.2018.09.25.13.44.22; Tue, 25 Sep 2018 13:44:38 -0700 (PDT) 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; 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 S1726417AbeIZCxh (ORCPT + 99 others); Tue, 25 Sep 2018 22:53:37 -0400 Received: from iolanthe.rowland.org ([192.131.102.54]:40370 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1726173AbeIZCxh (ORCPT ); Tue, 25 Sep 2018 22:53:37 -0400 Received: (qmail 7819 invoked by uid 2102); 25 Sep 2018 16:44:14 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 25 Sep 2018 16:44:14 -0400 Date: Tue, 25 Sep 2018 16:44:14 -0400 (EDT) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: Vladis Dronov cc: Andrey Konovalov , Greg Kroah-Hartman , Oliver Neukum , Hans de Goede , syzkaller , USB list , LKML , stable Subject: Re: [PATCH] usb: usbfs: fix crash in check_ctrlrecip()->usb_find_alt_setting() In-Reply-To: <1810191004.16066868.1537901713871.JavaMail.zimbra@redhat.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 25 Sep 2018, Vladis Dronov wrote: > > > What about adding a WARN_ON()? It doesn't crash the kernel and it will > > > be detected and reported by syzbot. > > Yes, that would be a great solution. > > > Sure, we could do that. But would be the point? > > We know when usb_find_alt_setting() callers do smth weird and go fix them. > > > After c9a4cb204e9e, calling usb_find_alt_setting() with a NULL config is > > no more of a bug than calling kfree() with a NULL pointer. > > Yes, exactly. > > > You wouldn't want to put a WARN_ON in kfree(), would you? > > Honestly, in the ideal world I would, again, to be aware when some code does > something weird so we know about it. But this world is this world, it needs > more performance to the throne of performance. But is it really worthwhile? In terms of catching bugs, this would help in only one situation: when the programmer thinks the argument should always be non-NULL because a NULL argument indicates a bug. Such situations seem to be relatively rare, and we can handle them by inserting a WARN_ON() at the call site if need be. So it's a choice between: 1. Putting a single test for NULL in the function being called, together with WARN_ON() at a small number of call sites, or 2. Putting a WARN_ON() (or allowing a crash) in the function being called, together with tests for NULL at a potentially large number of call sites. 1 has two advantages over 2. First, it involves adding less code overall. Second, it doesn't require the programmer to remember to add special code (a test or a WARN_ON) in situation where it doesn't matter -- presumably the majority of them. Now consider the case at hand: the call to usb_find_alt_setting() from check_ctrlrecip(). In this case ps->dev->actconfig being NULL doesn't indicate an error or a bug; it merely indicates that the user is trying to send a control request to a device which happens to be unconfigured, which is a perfectly valid thing to do. Therefore it shouldn't require any special handling at the call site. Alan Stern