Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2141067iof; Tue, 7 Jun 2022 21:07:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxu9ZhvR6TdK63kxfQtEB0ONutKmZEyl2nukNDHJOXn2UvYxlZfak+skEZUVGhnEXwSupww X-Received: by 2002:a65:604d:0:b0:3fc:57c8:e6eb with SMTP id a13-20020a65604d000000b003fc57c8e6ebmr29080378pgp.260.1654661233314; Tue, 07 Jun 2022 21:07:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654661233; cv=none; d=google.com; s=arc-20160816; b=Y48kyahP1zsHLF0onptKwLrI/0oBA056B/ATMl0Y1nYPC8WSDvlM3hwcBRqxH5J9n+ 0WMUnHisU7SK5B9vHxc6ohVsSH3fFJ2S8PfzcfF1ZXQS4LDhLG2jEJLZMBd0BiBH03zw nABpcL5rBPX9OW9v5e3wY2cDXl3XwZf0Cvc3CXpk6+6H/LhjdrVFSl43Nh3EPQeVWc4v MiBufW+WesYbhgkBA6JnS93TnxV8wbb2tIn2W2hxCw8c01c9VjLd/BE/EchPau2zdASp 8Q4IivhTQDK4oEoi63rnxtFJi1tLtwA09+amxzR8HNfMKceSXW5FWk6Mk33r1ASWMQhx haUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pCBotyaB+KYiNBSTPEFy6Kl29m4lpfJZXQTuWWnrjUQ=; b=gz5v402JHxV8ln7etUo9ebIWb6S+t6z5HY9lWPq32C9L4BBELWjgFGmbzIPMZcd76G wGTTLL+zRX65BtKW121rbhU6OQOlq22cE9eArfvyBkftZqOM3PQkUnt0rzrzkkJuX5AI lCewilhqFcZLSgBV4Vapf+B6vDT4BGArqHArGrcJPsPmM2XwfFur7xsxkJnyYqubL035 +CHYwok3tF8N/1Bjru3l3T1PLO20BSewR9PGFj4is3oNaZ4x5aVGjCyyCJb4QdzxGTVf Uoo9/eJ8l9eGDJpZIODQLfeK3rnIslBDodEnvgsgRYx+eNwoHkRZQrBgnh392em2EXHs MPLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1xXLzIq3; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id v17-20020a056a00149100b0051b51d8211fsi16772178pfu.91.2022.06.07.21.07.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 21:07:13 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1xXLzIq3; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1413E213A19; Tue, 7 Jun 2022 20:33:50 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1384957AbiFGWQ5 (ORCPT + 99 others); Tue, 7 Jun 2022 18:16:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380291AbiFGVLr (ORCPT ); Tue, 7 Jun 2022 17:11:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1885821913C; Tue, 7 Jun 2022 11:53:52 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8BE2E616C2; Tue, 7 Jun 2022 18:53:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97A6AC385A2; Tue, 7 Jun 2022 18:53:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654628031; bh=j8BlhbMW32GkhbU+NCT33qF/jy4hbgqTlQH7X9esMYA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1xXLzIq3MFpWYDnerzzpLpJonZA6BVupZ1CQM1egOx+4PBK88mr3tkdcAc6fetmVU g5URghORgCrQj7iUBrG/TzBH274MHvAPYCXR/q10mked2iYupwt84WXCGyIQojfGWf 0Y6+bw9Wv3fDyAVk66ksA0iYot7drogZFXK3tuJs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Haowen Bai , Corey Minyard , Sasha Levin Subject: [PATCH 5.18 154/879] ipmi:ssif: Check for NULL msg when handling events and messages Date: Tue, 7 Jun 2022 18:54:32 +0200 Message-Id: <20220607165007.176324279@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Corey Minyard [ Upstream commit 7602b957e2404e5f98d9a40b68f1fd27f0028712 ] Even though it's not possible to get into the SSIF_GETTING_MESSAGES and SSIF_GETTING_EVENTS states without a valid message in the msg field, it's probably best to be defensive here and check and print a log, since that means something else went wrong. Also add a default clause to that switch statement to release the lock and print a log, in case the state variable gets messed up somehow. Reported-by: Haowen Bai Signed-off-by: Corey Minyard Signed-off-by: Sasha Levin --- drivers/char/ipmi/ipmi_ssif.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c index f199cc194844..64c73ea9c915 100644 --- a/drivers/char/ipmi/ipmi_ssif.c +++ b/drivers/char/ipmi/ipmi_ssif.c @@ -814,6 +814,14 @@ static void msg_done_handler(struct ssif_info *ssif_info, int result, break; case SSIF_GETTING_EVENTS: + if (!msg) { + /* Should never happen, but just in case. */ + dev_warn(&ssif_info->client->dev, + "No message set while getting events\n"); + ipmi_ssif_unlock_cond(ssif_info, flags); + break; + } + if ((result < 0) || (len < 3) || (msg->rsp[2] != 0)) { /* Error getting event, probably done. */ msg->done(msg); @@ -838,6 +846,14 @@ static void msg_done_handler(struct ssif_info *ssif_info, int result, break; case SSIF_GETTING_MESSAGES: + if (!msg) { + /* Should never happen, but just in case. */ + dev_warn(&ssif_info->client->dev, + "No message set while getting messages\n"); + ipmi_ssif_unlock_cond(ssif_info, flags); + break; + } + if ((result < 0) || (len < 3) || (msg->rsp[2] != 0)) { /* Error getting event, probably done. */ msg->done(msg); @@ -861,6 +877,13 @@ static void msg_done_handler(struct ssif_info *ssif_info, int result, deliver_recv_msg(ssif_info, msg); } break; + + default: + /* Should never happen, but just in case. */ + dev_warn(&ssif_info->client->dev, + "Invalid state in message done handling: %d\n", + ssif_info->ssif_state); + ipmi_ssif_unlock_cond(ssif_info, flags); } flags = ipmi_ssif_lock_cond(ssif_info, &oflags); -- 2.35.1