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=-15.3 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 883DAC47094 for ; Thu, 10 Jun 2021 13:32:12 +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 322D5610C7 for ; Thu, 10 Jun 2021 13:32:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 322D5610C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:39976 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrKn5-0006ku-Bm for qemu-devel@archiver.kernel.org; Thu, 10 Jun 2021 09:32:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45852) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrKkF-0003KC-PV for qemu-devel@nongnu.org; Thu, 10 Jun 2021 09:29:15 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:2424) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrKkD-0000u0-0l for qemu-devel@nongnu.org; Thu, 10 Jun 2021 09:29:15 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4G14Vs3ZpszYsXV; Thu, 10 Jun 2021 21:26:13 +0800 (CST) Received: from dggema765-chm.china.huawei.com (10.1.198.207) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Thu, 10 Jun 2021 21:29:04 +0800 Received: from [10.174.185.187] (10.174.185.187) by dggema765-chm.china.huawei.com (10.1.198.207) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Thu, 10 Jun 2021 21:29:03 +0800 Subject: Re: [PATCH] vl: Fix an assert failure in error path To: Markus Armbruster References: <20210610084741.456260-1-zhenzhong.duan@intel.com> <048a18be-0d1c-7fd0-7031-51e64c5432f3@redhat.com> <87fsxrnss4.fsf@dusky.pond.sub.org> <2a094460-5549-4a64-8df0-c376e046b012@huawei.com> <87v96mfa3d.fsf@dusky.pond.sub.org> From: Peng Liang Message-ID: <2d160878-add1-9c68-f0c2-b67723dce056@huawei.com> Date: Thu, 10 Jun 2021 21:29:03 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.2.2 MIME-Version: 1.0 In-Reply-To: <87v96mfa3d.fsf@dusky.pond.sub.org> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.185.187] X-ClientProxiedBy: dggeme707-chm.china.huawei.com (10.1.199.103) To dggema765-chm.china.huawei.com (10.1.198.207) X-CFilter-Loop: Reflected Received-SPF: pass client-ip=45.249.212.187; envelope-from=liangpeng10@huawei.com; helo=szxga01-in.huawei.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_NONE=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 , =?UTF-8?Q?Daniel_P=2e_Berrang=c3=a9?= , Zhenzhong Duan , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On 6/10/2021 3:32 PM, Markus Armbruster wrote: > Peng Liang writes: > >> On 6/9/2021 8:15 PM, Daniel P. Berrangé wrote: >>> On Wed, Jun 09, 2021 at 02:09:47PM +0200, Markus Armbruster wrote: >>>> Paolo Bonzini writes: >>>> >>>>> On 10/06/21 10:47, Zhenzhong Duan wrote: >>>>>> Based on the description of error_setg(), the local variable err in >>>>>> qemu_maybe_daemonize() should be initialized to NULL. >>>>>> Without fix, the uninitialized *errp triggers assert failure which >>>>>> doesn't show much valuable information. >>>>>> Before the fix: >>>>>> qemu-system-x86_64: ../util/error.c:59: error_setv: Assertion `*errp == NULL' failed. >>>>>> After fix: >>>>>> qemu-system-x86_64: cannot create PID file: Cannot open pid file: Permission denied >>>>>> Signed-off-by: Zhenzhong Duan >>>>>> --- >>>>>> softmmu/vl.c | 2 +- >>>>>> 1 file changed, 1 insertion(+), 1 deletion(-) >>>>>> diff --git a/softmmu/vl.c b/softmmu/vl.c >>>>>> index 326c1e9080..feb4d201f3 100644 >>>>>> --- a/softmmu/vl.c >>>>>> +++ b/softmmu/vl.c >>>>>> @@ -2522,7 +2522,7 @@ static void qemu_process_help_options(void) >>>>>> static void qemu_maybe_daemonize(const char *pid_file) >>>>>> { >>>>>> - Error *err; >>>>>> + Error *err = NULL; >>>> >>>> Common mistake, I'm afraid. >>> >>> Initializing isn't likely to be a performance impact, so I'd think >>> we should make 'checkpatch.pl' complain about any 'Error *' variable >>> that is not initialized to NULL, as a safety net, even if not technically >>> required in some cases. >>> >>> Regards, >>> Daniel >>> >> >> Hi, >> Could we add a coccinelle script to check (and fix) these problems? e.g.: > > Coccinelle is good for finding and fixing instances of bad patterns that > have crept in. checkpatch is good for keeping them out. Both has its > uses. > >> @ r @ >> identifier id; >> @@ >> Error *id >> + = NULL >> ; >> >> Using this script, I found that local variable err in >> qemu_init_subsystems is not initialized to NULL too. > > Crash bug, broken in commit efd7ab22fb "vl: extract > qemu_init_subsystems", v6.0.0. Care to submit a fix? Have sent :) > >> The script is not >> prefect though, it will initialize all global/static 'Error *' variables >> and all local 'Error *' variables in util/error.c to NULL, which is >> unnecessary. > > Excluding util/error.c is easy once you know how to: > > @ depends on !(file in "util/error.c")@ > identifier id; > @@ > ... > > Excluding variable definitions with static storage duraction shouldn't > be too hard, either. If Coccinelle is sufficiently clever, adding > keyword auto suffices. Else, try matching keyword static separately, > like so: > > ( > static Error *id; > | > - Error *id; > + Error *id = NULL; > ) > > Completely untested. > Thanks for your improvement! Thanks, Peng