Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp139790imb; Thu, 28 Feb 2019 18:48:25 -0800 (PST) X-Google-Smtp-Source: APXvYqwYEdAgo6iCYtc1j5fgWE4L7lWSPsFq5OqEmcYfN0ywsHWj7bZeNwCnVLdY6TFWDJVH7mpN X-Received: by 2002:a65:624a:: with SMTP id q10mr2538804pgv.377.1551408505004; Thu, 28 Feb 2019 18:48:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551408504; cv=none; d=google.com; s=arc-20160816; b=XgxLJ5tXhk4w5h0KDdkYcedzpx/lUBpxoxOw0IrBLhhoHH7JoHa2DAtGRmpKUCvO0W nsWPt2jDq+N0E97z7lDqMrXHF/oOFoJ9VGrJCuZdCwi05lrIbVhsROgCU1J8gxdUKytZ WI8zElbSyqRtspH/zNBE0tMEdOwLpvWi0eLpldTSg81qfGn0EXZGX4NZ5VbKiBwplmvN XAioCEE2weUB3iNf15s1Vpoa96TkdVGMrkTOadAvo8P5vpT8wP+fLF4WZfBEXP7eyh1A UYGqVTiHCdjM2K7QNWHI2wj0kGliXZldA4NkagaX/6prrKjfQR2nIN5cIlzbISu5lKwY /ggw== 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; bh=pFgm7tTTgz2FjWFgELZoYmKu5m6/qw3Dar8QeEcoWwk=; b=h2Z9TitUJym2NJQwIrJVgu7zr3BgPpvCJxYK4F21bnRCiGiI5AjCenJfky6q/nz//e HJG8IQCrGZqWZqQC7Ur2NHhN5vJVTWEBIfCnhE3COFq987c/VoeM/KScpVfmjxfGvzoZ K5Z42g0HAYU9lC1IrSSXgecM5U/7wzEQKDCqQ7tfBDfrPQmEARn2Bj6QqHEhSHs7kEE9 pQ2WvLGZ5l9CowSswjJz6RT0yiNQwrRHZQHZjQZCMjIf2oqjExyk0tKaJn/38bWuzVzI snpHBvQ2OsunBb6wX8oqa/pzM2tVumV9IlQHIscmjuc6U6S4Y/bG/e3aBMZX6ORQmVwN u6ww== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=utah.edu Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h62si20321657pfb.143.2019.02.28.18.48.09; Thu, 28 Feb 2019 18:48:24 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=utah.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729606AbfB1X5I (ORCPT + 99 others); Thu, 28 Feb 2019 18:57:08 -0500 Received: from mail-svr1.cs.utah.edu ([155.98.64.241]:36815 "EHLO mail-svr1.cs.utah.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725955AbfB1X5I (ORCPT ); Thu, 28 Feb 2019 18:57:08 -0500 Received: from localhost (localhost [127.0.0.1]) by mail-svr1.cs.utah.edu (Postfix) with ESMTP id 3F13E6500BF; Thu, 28 Feb 2019 16:57:07 -0700 (MST) Received: from mail-svr1.cs.utah.edu ([127.0.0.1]) by localhost (mail-svr1.cs.utah.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8qXCwX2cOliC; Thu, 28 Feb 2019 16:57:06 -0700 (MST) Received: from [155.98.67.65] (kalnik.cs.utah.edu [155.98.67.65]) by smtps.cs.utah.edu (Postfix) with ESMTPSA id B6E1C6500B9; Thu, 28 Feb 2019 16:57:06 -0700 (MST) Subject: Re: [PATCH] cxgb4: fix undefined behavior in mem.c To: Bart Van Assche , linux-rdma@vger.kernel.org Cc: Steve Wise , Doug Ledford , Jason Gunthorpe , open list References: <1551393519-96595-1-git-send-email-shaobo@cs.utah.edu> <1551394596.31902.209.camel@acm.org> <1551396788.31902.213.camel@acm.org> From: Shaobo He Message-ID: Date: Thu, 28 Feb 2019 16:57:06 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.2 MIME-Version: 1.0 In-Reply-To: <1551396788.31902.213.camel@acm.org> Content-Type: text/plain; charset=utf-8; format=flowed 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 Good catch. But if we agree on that memory management functions are those specified by the C standard, would it be OK to ignore so-called use after free or double free bugs for the kernel as C standard does not apply to kfree? On 2/28/19 4:33 PM, Bart Van Assche wrote: > On Thu, 2019-02-28 at 16:18 -0700, Shaobo He wrote: >> I can't afford a pdf version of the C standard. So I looked at the draft version >> used in the link I put in the commit message. It says (in 6.2.4:2), >> >> ``` >> The lifetime of an object is the portion of program execution during which >> storage is guaranteed to be reserved for it. An object exists, has a constant >> address, and retains its last-stored value throughout its lifetime. If an object >> is referred to outside of its lifetime, the behavior is undefined. The value of >> a pointer becomes indeterminate when the object it points to (or just past) >> reaches the end of its lifetime. >> ``` >> I couldn't find the definition of lifetime over a dynamically allocated object >> in the draft of C standard. I refer to this link >> (https://en.cppreference.com/w/c/language/lifetime) which suggests that the >> lifetime of an allocated object ends after the deallocation function is called >> upon it. >> >> I think maybe the more problematic issue is that the value of a freed pointer is >> intermediate. > > In another section of the same draft I found the following: > > J.2 Undefined behavior [ ... ] The value of a pointer that refers to space > deallocated by a call to the free or realloc function is used (7.22.3). > > Since the C standard explicitly refers to free() and realloc(), does that > mean that that statement about undefined behavior does not apply to munmap() > (for user space code) nor to kfree() (for kernel code)? > > Bart. >