Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2576982ybm; Thu, 23 May 2019 20:37:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqzIssDIlOsRrUAgkgDVw2KNxH5xdj/Rx3xQBkAhvJmG//R2R/ydpWv3D9aekbuMKY84B8vn X-Received: by 2002:a17:90a:9b8b:: with SMTP id g11mr6169836pjp.103.1558669028772; Thu, 23 May 2019 20:37:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558669028; cv=none; d=google.com; s=arc-20160816; b=mb4PpKr5yy8fcmCoXsU67rUvysgNJkteRy6MbNAMcLDOiP3QGbzD1YPO0Jw8+6OVzw uVYQ9zchoE0LA18ImmDiepVLXLEvMosPBgB9q/ONV5o4oqaT6+xSe00KQcgtKamI/WpO 3omkWRN6B63iqRt9oNETcL4WHW2VjUP6YFrEyLSzixQWwv9WczavsB31fIfxnOSjPA8I hYcYxq1lS7g0OpjWtPxtst4fpK4MKA/dPoCCNiYCca6Oc/9Z8XVg2Stu08U1H9T89L3Q teEn/dmtxAmt1zlCyrZkQ5McNwH3V1QYbnBvgAsQAOjCYhslkzMbYSFPyoPQRvSLBNbu sUxA== 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:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=0U3jtShjjiJN3ps1pNI0W/EiDaSwxuW6+iMQ/EY3Dmk=; b=PQb5khizFWO332Opv7V5xDwoncJHh42MmIUkz3ghRF+0hoF+SAq62sTiGrQogj37gY olQATXf15EM9CCEHmAxjm+a2PybLw8Ucr2pcEGQHPu6kekFyenEW8xya5cGbinjuz7ZU Xnt9g4j2Vi9JsdtrEOXcu1K4vYvQyHY+dlDVpjSfxRpsz6Y6wNxDmWkBUQ5oXUJuLdMs hKAFEacqTussaPHRmfvosrDX/sftfp6oJRg+ujBmmgcy33qx26MEF2Sk+qWlB3hu/Qo8 NFTLAX2HYuPAyxWG/S/n/9CZFcBobj6GMxtGP0TSEqjKhzDfJvYRlFoKLzdouxNtcEWX oAKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jDvnv6tp; 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 z5si2296460plh.219.2019.05.23.20.36.48; Thu, 23 May 2019 20:37:08 -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; dkim=pass header.i=@kernel.org header.s=default header.b=jDvnv6tp; 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 S2387928AbfEXDfZ (ORCPT + 99 others); Thu, 23 May 2019 23:35:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:44536 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387559AbfEXDfZ (ORCPT ); Thu, 23 May 2019 23:35:25 -0400 Received: from localhost.localdomain (c-73-223-200-170.hsd1.ca.comcast.net [73.223.200.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F32F42133D; Fri, 24 May 2019 03:35:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558668924; bh=GbrlHKi71gaVsN79M3+9tkZQr3yHgBtNIIbYV9ulLS0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=jDvnv6tpy2BH/IrlaiJ8KlyFoOOljEmmW5ldVVIqoKOdBfDVA5/5n+eWzf29LjIXF /C/g7IqdobNb0zQtemFkAjy7UP66ezdDoX+0GHtiIQL5BiEWE/VEBErHnmXjuBSaze b2uGxIwsCPkUNuxboZF+aIC0bPy92DqHazUsWteY= Date: Thu, 23 May 2019 20:35:23 -0700 From: Andrew Morton To: Gen Zhang Cc: rppt@linux.ibm.com, david.engraf@sysgo.com, steven.price@arm.com, osandov@fb.com, luc.vanoostenryck@gmail.com, axboe@kernel.dk, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] initramfs: Fix a missing-chek bug in dir_add() Message-Id: <20190523203523.8f638f378b54df0ef7a18f9d@linux-foundation.org> In-Reply-To: <20190524033045.GA6628@zhanggen-UX430UQ> References: <20190524033045.GA6628@zhanggen-UX430UQ> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 24 May 2019 11:30:45 +0800 Gen Zhang wrote: > In dir_add() and do_name(), de->name and vcollected are allocated by > kstrdup(). And de->name and vcollected are dereferenced in the following > codes. However, memory allocation functions such as kstrdup() may fail. > Dereferencing this null pointer may cause the kernel go wrong. Thus we > should check these two kstrdup() operations. > Further, if kstrdup() returns NULL, we should free de in dir_add(). We generally assume that memory allocations within __init code cannot fail. If one does fail, something quite horrid has happened. The resulting oops will provide the same information as the proposed panic() anyway.