From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB92FECE58A for ; Tue, 1 Oct 2019 15:13:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BB7A1206BB for ; Tue, 1 Oct 2019 15:13:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389470AbfJAPN0 (ORCPT ); Tue, 1 Oct 2019 11:13:26 -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-Google-Smtp-Source: APXvYqxyVJmic1F+7fZfFZQAxNcXMB5Z/ocNdDnPHOVjj8h1tH2nOU0MyL/PgaJMMnw3AF2+JFzzgw== 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