Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp578587pxk; Wed, 16 Sep 2020 11:15:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwiZp8DewgCxl3mcJtWfOHyl9/GFH2wqYhh6JxEF8SQ+meJAv88SrTVjK6TJxvhnvmmc1xp X-Received: by 2002:a17:906:b146:: with SMTP id bt6mr26391113ejb.287.1600280142787; Wed, 16 Sep 2020 11:15:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600280142; cv=none; d=google.com; s=arc-20160816; b=I1RiLNpWfd4A7gzc2BkY6b21EnVrFsYtJ/eFULTzdIfMfmgM4d2gCgIOUrgezQzdAT e4nut6VMLj33QwXAHlztOGKVPPveJFBd3kX/onT4gRSYgimfJztKfEYLNLlM3hK5T1xC Hxmmv0E2/5xPE00Z81yVp59ChYXuUmN/rd7XJLOypx7PH+WOQryfAlQxoiXxram21sxi yaaOhVpXcvuDN5Fp5VKIVdKDjk8bMhaqrzvZNVHFEWJ3Cydt02ccGCCb3vnsDpcUjnbr 0EFxIrJEyjnUClifNvYI0Y+wmf6ACibVWYQWAzM40lGtNB1gefO2uia7ssCYJNk1+k7G MupQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=RPMmBa/zuVIVa6YT0Ct/PRYo3W8xK4AI2YIowuyMAz8=; b=m/MDp3Tql1SvWBw20Le7CVAzsrbblZKQqk2JRD+TUePmJYt4jw/ctvnHSXAZWM2k68 CCPtUvWkNhMM+vC7tGrhXBflCGUa+ShONKZztAXyCpxR3xKyLy33Gl4Sw5tGuuBB45qK Puu2xW742QRoerqJgyuzya5UkL3LBqLhVo2BQpTIRo2q7dPU8psZ3cXdSNInsZg3gsc1 D8LeCG09GYHYXiFPFs2EJd7FEWL3OsT9XhsNZGcuyWMnLKRGkqmtxv+YgIpYX3M3DtPl UXvvh2NFOQyguwHaeNuU6uVbchPB3mWAYFydLhP0pFpARvlSTudOZ0oTvCwPxcg/m+OM +wbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fHilp9TK; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f23si12574942edm.413.2020.09.16.11.15.20; Wed, 16 Sep 2020 11:15:42 -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=@gmail.com header.s=20161025 header.b=fHilp9TK; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727739AbgIPSOa (ORCPT + 99 others); Wed, 16 Sep 2020 14:14:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727647AbgIPSMx (ORCPT ); Wed, 16 Sep 2020 14:12:53 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E26F1C014D06; Wed, 16 Sep 2020 06:38:27 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id 34so3885592pgo.13; Wed, 16 Sep 2020 06:38:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=RPMmBa/zuVIVa6YT0Ct/PRYo3W8xK4AI2YIowuyMAz8=; b=fHilp9TKndRfRIpIEW7pskStpJIx9tJimZ/y0pA9ypEvUHuYNm+18QlWmYOouD1tX0 LCK9aNAEI5YK+8CxLy6PgjIyLZmIZKfqvdx8B+9dwUnu8GnDSki3ejFJDcxMtw4ZvZkD o58I2PumQyjbrEwCBsQvpOvIod2iRymYkDGLSlbDNe4W6UpmWWVqCwY2nBO6TgvF0l4g KHU2qC9MgZICr7bfyPlIUWcx9aqQb6z72coEyRXs4xC52mJuXIJ47/9zIuWZe9xlXciN rWrQ0jdnFJUZre4qzzTb/8uUrDgfCghNIQGgFqFdkhyrVn5mG75WLqiOFP8ZrHLbyxL8 NelQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=RPMmBa/zuVIVa6YT0Ct/PRYo3W8xK4AI2YIowuyMAz8=; b=jfTHcUUvW1CA4vlmQzW1747Vme3acmyrR3wNr4HC65JdygXqIXH7fDntCYyEB+f4i8 QOTQNC6c28ILk0iygOtM069qUUUne4a3FBHnWoT05EQUq3zaNhp635qY/iX5GOj2OneX kUtt8blkzqNfd/fYrsDofD7iD4au/6oi/Ywr73rYPRzzoXfdz0hMAk2enY6UVBlXSFf9 AL4KJLZx0ONwZ+GA9hIcgPg3I37DQErwYXyJv2jeW6uLdTyrrYmaoE5t7HKfP0FxbL+Z 0dT5Oq/iFHY9g7QA6qJso1RCbzaN5FBHMSoaH1YiOJQ8ewHZWJKr+gF0BPR0QOMIDXol 0X5w== X-Gm-Message-State: AOAM531Dw56MEgBasnOcUr5nIuOy12nC75STWwx/VKsehDoX4SYaetoC AcfZy4lkMfMbgI3cSMSomRkrRNVSgiKjVukRLFE= X-Received: by 2002:a63:30c:: with SMTP id 12mr18613171pgd.66.1600263506704; Wed, 16 Sep 2020 06:38:26 -0700 (PDT) Received: from [192.168.0.104] ([49.207.198.18]) by smtp.gmail.com with ESMTPSA id e62sm16987968pfh.76.2020.09.16.06.38.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 16 Sep 2020 06:38:26 -0700 (PDT) Subject: Re: [Linux-kernel-mentees][PATCH] rtl8150: set memory to all 0xFFs on failed register reads To: Petko Manolov Cc: linux-kernel-mentees@lists.linuxfoundation.org, syzbot+abbc768b560c84d92fd3@syzkaller.appspotmail.com, "David S. Miller" , Jakub Kicinski , linux-usb@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org References: <20200916050540.15290-1-anant.thazhemadam@gmail.com> <20200916061946.GA38262@p310> From: Anant Thazhemadam Message-ID: <780e991d-864d-0491-f440-12a926920a8a@gmail.com> Date: Wed, 16 Sep 2020 19:08:21 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200916061946.GA38262@p310> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 16/09/20 11:49 am, Petko Manolov wrote: > On 20-09-16 10:35:40, Anant Thazhemadam wrote: >> get_registers() copies whatever memory is written by the >> usb_control_msg() call even if the underlying urb call ends up failing. > Not true, memcpy() is only called if "ret" is positive. Right. I'm really sorry I fumbled and messed up the commit message there. Thank you for pointing that out. >> If get_registers() fails, or ends up reading 0 bytes, meaningless and junk >> register values would end up being copied over (and eventually read by the >> driver), and since most of the callers of get_registers() don't check the >> return values of get_registers() either, this would go unnoticed. > usb_control_msg() returns negative on error (look up usb_internal_control_msg() > to see for yourself) so it does not go unnoticed. When I said "this would go unnoticed", I meant get_register() failing would go unnoticed, not that usb_control_msg() failing would go unnoticed. I agree that get_registers() notices usb_control_msg() failing, and appropriately returns the return value from usb_control_msg(). But there are many instances where get_registers() is called but the return value of get_registers() is not checked, to see if it failed or not; hence, "this would go unnoticed". > If for some reason it return zero, nothing is copied. Also, if usb transfer fail > no register values are being copied anywhere. True. Now consider set_ethernet_addr(), and suppose get_register() fails when invoked from inside set_ethernet_addr(). As you said, no value is copied back, which means no value is copied back into node_id, which leaves node_id uninitialized. This node_id (still uninitialized) is then blindly copied into dev->netdev->dev_addr; which is less than ideal and could also quickly prove to become an issue, right? > Your patch also allows for memcpy() to be called with 'size' either zero or > greater than the allocated buffer size. Please, look at the code carefully. Oh. I apologize for this. This can be reverted relatively easily. >> It might be a better idea to try and mirror the PCI master abort >> termination and set memory to 0xFFs instead in such cases. > I wasn't aware drivers are now responsible for filling up the memory with > anything. Does not sound like a good idea to me. Since we copy the correct register values when get_register() doesn't fail, I thought it might be a slightly better alternative to fill node_id with 0xFFs, instead of leaving it go uninitialized in case get_registers() fails. Also, what are the odds that a successful get_register() call would see 0xFFs being copied? If that's very real scenario, then I admit this doesn't work at all. The only other alternative approach I can think of that can handle the issue I highlighted above, is to introduce checking for get_registers()'s return values nearly everywhere it gets called. Would that be a more preferable and welcome approach? Thank you for your time. Thanks, Anant