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=-15.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham 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 2D9ADC4338F for ; Fri, 13 Aug 2021 07:26:51 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B81186103E for ; Fri, 13 Aug 2021 07:26:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B81186103E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:34220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mERab-0003wv-O5 for qemu-devel@archiver.kernel.org; Fri, 13 Aug 2021 03:26:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42274) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mERYx-0002l1-KK for qemu-devel@nongnu.org; Fri, 13 Aug 2021 03:25:07 -0400 Received: from mga12.intel.com ([192.55.52.136]:63572) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mERYv-0008Gk-C8 for qemu-devel@nongnu.org; Fri, 13 Aug 2021 03:25:07 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10074"; a="195104792" X-IronPort-AV: E=Sophos;i="5.84,318,1620716400"; d="scan'208";a="195104792" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Aug 2021 00:24:57 -0700 X-IronPort-AV: E=Sophos;i="5.84,318,1620716400"; d="scan'208";a="485845522" Received: from jingqili-mobl.ccr.corp.intel.com (HELO [10.254.208.91]) ([10.254.208.91]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Aug 2021 00:24:56 -0700 Subject: Re: [PATCH] softmmu/physmem.c: Check return value from realpath() To: Peter Maydell , "qemu-devel@nongnu.org" References: <20210812151525.31456-1-peter.maydell@linaro.org> From: "Liu, Jingqi" Message-ID: Date: Fri, 13 Aug 2021 15:24:45 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <20210812151525.31456-1-peter.maydell@linaro.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=192.55.52.136; envelope-from=jingqi.liu@intel.com; helo=mga12.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On 8/12/2021 11:15 PM, Peter Maydell wrote: > The realpath() function can return NULL on error, so we need to check > for it to avoid crashing when we try to strstr() into it. > This can happen if we run out of memory, or if /sys/ is not mounted, > among other situations. > > Fixes: Coverity 1459913, 1460474 > Fixes: ce317be98db0 ("exec: fetch the alignment of Linux devdax pmem character device nodes") > Signed-off-by: Peter Maydell > --- > softmmu/physmem.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/softmmu/physmem.c b/softmmu/physmem.c > index c47cb6da2e4..eb0595d57c4 100644 > --- a/softmmu/physmem.c > +++ b/softmmu/physmem.c > @@ -1451,6 +1451,9 @@ static int64_t get_file_align(int fd) > path = g_strdup_printf("/sys/dev/char/%d:%d", > major(st.st_rdev), minor(st.st_rdev)); > rpath = realpath(path, NULL); > + if (!rpath) { > + return -errno; > + } Good find! Reviewed-by: Jingqi Liu Thanks, Jingqi