Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp8450591ybn; Tue, 1 Oct 2019 08:16:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqxiRE3qY0mZtdEIEKBndQoBZmzmIFaPw/c1AVxfuRZyVwB9OG7yPTl/qb2kKVUzbb/1M6mg X-Received: by 2002:a05:6402:1251:: with SMTP id l17mr26365623edw.270.1569943015511; Tue, 01 Oct 2019 08:16:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569943015; cv=none; d=google.com; s=arc-20160816; b=HBVuYnGAuT2hPIOTSNqbuTOOhZTgmQlZDqLPJ3FTu3dvMKt+FQSRvyd5Jf7n+xOp2t u78W1W/c8SVtsXhPhWeeoqsode4SY1jzwB3TLCCrnBzYe1BjflHZJ028D21vBHIxu1fU fkfBETghlTED/vh7Z0YfdYQSovkiwwjMYc4WdNyt79Vu3DWxgKbPswEW8XFJze6uYQtI +Y1Ri458EqhEZKksX9Z8p/QbPfTVeHa/j4hxsogfNNZG4oCZ2v+BGEtRMCMYJTetnRq0 HZrUQg3RYTiW9MulVuEZCbaqcVbRffsgr1qWK/QCnlD8jDwBOQaKwYU2KE93UF1TtOM5 Y8Rw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:reply-to; bh=N2FlzG+PxQCjT3jm2D3Aa1IldYkDzjEnGNfZ4YLjVII=; b=Y2WLOgPUm+PS+VDXJBR3OJpVy5YxUR/pEEugGLZ+IXMeyUWNT15LeJsaxSIwWqfxUQ 4mXvrw/JQcIAotMdufYoXwIqr0E0QQR2zcfMDTQMqe/K270Vx+4ymqvp7VRQMVAX+xQi JB2sf7SDiq8NN7uZpzWw3CaZ/zfL203m/7a9NcyjuyptMBkYV64QkmbrF3P8FCESpmS3 TrSsGPw1Y83/sNFmeqyx/a+md2HMNjWZG6kr/UOQb0RiSjgdd+z9yKWsJCzRV5Mfo0fx A2ODsYvHZOsYA9mz6uZB/rJguHETzLJOD3R3r3IWEQpIMIgBghDbujO2lN2jvZ0K7oat OfLw== 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 r24si8684512edy.417.2019.10.01.08.16.30; Tue, 01 Oct 2019 08:16:55 -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 S2389454AbfJAPNZ (ORCPT + 99 others); Tue, 1 Oct 2019 11:13:25 -0400 Received: from mail-ed1-f65.google.com ([209.85.208.65]:36252 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727179AbfJAPNZ (ORCPT ); Tue, 1 Oct 2019 11:13:25 -0400 Received: by mail-ed1-f65.google.com with SMTP id h2so12277732edn.3; Tue, 01 Oct 2019 08:13:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:subject:to:cc:references:from :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=N2FlzG+PxQCjT3jm2D3Aa1IldYkDzjEnGNfZ4YLjVII=; b=GTLlE36emsyfwlCmg5/qd+JCYVMMKgASzsy4gmL+XPeskYqSSSuJISrQ3A6dDD7t+9 F+V7XPh7bQttfJku/JHEpVwBQdsQQK174lSegpomZrTGIBleXS809G6+RrucB2/3PzNO cCYYCOnMZsOQT9+5ORElE7x4qrE9o8Bn37g1s63AU426pysTPJUrGDbwBlITeZVQer3j FYTPzJ90dbeNq4eySZ/SgEs+CBE5/r0k9F77oFU1jHeGvMYp5Vw+93okzSpvVVdLJPPU 7VcncYpfqwPxiELEb/1orqM2ZE866YdWQhnd4MEt4FXsly+RE1c4W6iJvHb7xo7D7/JR 1ToA== X-Gm-Message-State: APjAAAUN0a3/RbdDZc9uQhr0wn9Sq3kAP9A7+8fUdt5/EMCoCjUzo1gd 87ZBNk48IMxh1PLYBoO+8TA= X-Received: by 2002:a17:906:7802:: with SMTP id u2mr15475439ejm.3.1569942803627; Tue, 01 Oct 2019 08:13:23 -0700 (PDT) Received: from [10.10.2.174] (bran.ispras.ru. [83.149.199.196]) by smtp.gmail.com with ESMTPSA id gl4sm1878601ejb.6.2019.10.01.08.13.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Oct 2019 08:13:23 -0700 (PDT) Reply-To: efremov@linux.com Subject: Re: [PATCH] staging: rtl8723bs: hal: Fix memcpy calls To: David Laight , 'Dan Carpenter' Cc: "devel@driverdev.osuosl.org" , Jes Sorensen , Greg Kroah-Hartman , "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" , Hans de Goede , Bastien Nocera , Dmitry Vyukov , Larry Finger References: <20190930110141.29271-1-efremov@linux.com> <37b195b700394e95aa8329afc9f60431@AcuMS.aculab.com> <20191001135649.GH22609@kadam> <8d2e8196cae74ec4ae20e9c23e898207@AcuMS.aculab.com> From: Denis Efremov Message-ID: Date: Tue, 1 Oct 2019 18:13:21 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.0 MIME-Version: 1.0 In-Reply-To: <8d2e8196cae74ec4ae20e9c23e898207@AcuMS.aculab.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/1/19 5:36 PM, David Laight wrote: >> From: Dan Carpenter >> Sent: 01 October 2019 14:57 >> Subject: Re: [PATCH] staging: rtl8723bs: hal: Fix memcpy calls > ... >> That's true for glibc memcpy() but not for the kernel memcpy(). In the >> kernel there are lots of places which do a zero size memcpy(). > > And probably from NULL (or even garbage) pointers. > > After all a pointer to the end of an array (a + ARRAY_SIZE(a)) is valid > but must not be dereferenced - so memcpy() can't dereference it's > source address when the length is zero. > >> The glibc attitude is "the standard allows us to put knives here" so >> let's put knives everywhere in the path. And the GCC attitude is let's >> silently remove NULL checks instead of just printing a warning that the >> NULL check isn't required... It could really make someone despondent. > > gcc is the one that add knives... > Just found an official documentation to this issue: https://gcc.gnu.org/gcc-4.9/porting_to.html "Null pointer checks may be optimized away more aggressively ... The pointers passed to memmove (and similar functions in ) must be non-null even when nbytes==0, so GCC can use that information to remove the check after the memmove call. Calling copy(p, NULL, 0) can therefore deference a null pointer and crash." But again, I would say that the bug in this code is because the if condition was copy-pasted and it should be inverted. Thanks, Denis