Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2138821iof; Tue, 7 Jun 2022 21:03:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7uqMe6+3/mYgOE201hMso/jXPiCldiF70KxBMi2sW8U6j7FHTH6mpZMFUTTTKzQ9Rt833 X-Received: by 2002:a17:902:bb90:b0:156:2c05:b34f with SMTP id m16-20020a170902bb9000b001562c05b34fmr32706282pls.53.1654661002842; Tue, 07 Jun 2022 21:03:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654661002; cv=none; d=google.com; s=arc-20160816; b=fzduW1dLISfS1LsQW8qbBcSO608THfgv7yarDXsqTDaumgdMbT8rN+K54BBRusEeGw FaEMIxGPKzUsYW5niC2XsFv/5dlll15aMqDemqR54ydpNAKearLTJ7a5GEoA5kk1/jYu 5zvoowUOGruJoSKwxTMH5jRkIu7MTI1AzIoeCYxNJHG1sZn5UkibSZ4DyIG0V/8U40pj 9fYX1GiK7FEsXilqJBrrOG7LnXmkBHZpYxue1pV0oXFUGy8zXLqMj6dZtJqRzMdxzNqk N+WO2jclI+9whj4awaW73LPjiXXFkegld6yv8BOrXkd03fHyIASSyyGHQ0ApKgVThE9G ewWA== 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=96iMaPuBu7I1Ec+zjZjC5ewucbn1ZmmgfhEBnOiRbEI=; b=w5lHYrGwvegO2JtJq6sXvC3delB6IiG+q78v4+RCCwpkRWHicDPUCdNTW7MevASD5Y 5WMABK39NsfOuPhZUyTkRxt97dvgA3/EpvHMSZ97u6fWaTCDeDkCMa0VlSXnY63k1isk lDhMNnO57UYj76u4a5pwzdF8pGxdRVQoqlSrxtOPq8zuW4dBOvbBa6bQtYKGGu4F4pA3 UhRolo6RwzKG+KoigH245alnV7o9qEttCiZN0X54CiXXCVGeNFf/NeifGGdCriSMjX8m AGgFjZB4mb32Gt1spFvWqJ3WmuMvRSKWFl/zX2rqeNncaCU60h86O3x7cvBkI2zFrW2j Xzww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tGqQhp9v; 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 d1-20020a63f241000000b003db238f2a93si27682309pgk.815.2022.06.07.21.03.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 21:03:22 -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=tGqQhp9v; 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 4FAF4212DBB; Tue, 7 Jun 2022 20:27:59 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347184AbiFGReO (ORCPT + 99 others); Tue, 7 Jun 2022 13:34:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346795AbiFGRZ3 (ORCPT ); Tue, 7 Jun 2022 13:25:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EFFA1105F0; Tue, 7 Jun 2022 10:23:13 -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 9AC5860906; Tue, 7 Jun 2022 17:23:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE45BC34115; Tue, 7 Jun 2022 17:23:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654622592; bh=9FbQtXO0L8JxJMcpmuh7ZMfZkX+/jwdeHsLIxezS240=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tGqQhp9v/7THIBa5yy6sODQt2dnRFSF5AP6fwoVRsYhnEUM4dGLLaOreKw5NdskIb l+tWs6Go/emnSP2rF1gIaAdK8ZjD//4g5IXIbG41lk/4UXl1dOZl2lRuK4A3ymZvIv ERcpym8seRwYUi4m1ogKg3vF5MIufFEC0oFsE5Sk= 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.10 074/452] ipmi:ssif: Check for NULL msg when handling events and messages Date: Tue, 7 Jun 2022 18:58:51 +0200 Message-Id: <20220607164910.758319218@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607164908.521895282@linuxfoundation.org> References: <20220607164908.521895282@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 3de679723648..477139749513 100644 --- a/drivers/char/ipmi/ipmi_ssif.c +++ b/drivers/char/ipmi/ipmi_ssif.c @@ -840,6 +840,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); @@ -864,6 +872,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); @@ -887,6 +903,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