Received: by 2002:a19:771d:0:0:0:0:0 with SMTP id s29csp1235688lfc; Wed, 1 Jun 2022 12:36:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzb80pJf6+Adke23wqBU/xCSJNOx4Rdwkuf+IE21nJD6rc0XN9Yym7wgvd4TGpgA5pDo4JO X-Received: by 2002:a17:90b:38c2:b0:1e0:44ca:8de6 with SMTP id nn2-20020a17090b38c200b001e044ca8de6mr958914pjb.243.1654112197104; Wed, 01 Jun 2022 12:36:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654112197; cv=none; d=google.com; s=arc-20160816; b=SBq1YDLvvaXt4YkYkbJtqAiAZWGZ5L/vrZXyRVlyUqPYlp6TRpwcF9dn3+hGfB7pax jqdJziTKMSFuE7VdjWej0tg+J5PHYzeqRNrzujcJgm/8GTLHkjGaWruH+vZc0BAT6l8U 7mMRy8irf3OR0ECEOcLt8kSeXCOaNbq8yPRvGT24071w9yb3L6MCApaVgcQyFd7CFzat jdWIhgP5ll0GecEYUF5ICRpqE+UpHb0/IjUYYR9y8txwMqInJ7yi3X4TAoiWYd7m0ulw WhOC2M1rn2mraG1QTnVEH8gT40U3rhX7kI0fSEQB+4BtEXfVJQqujV2rTGZBB5xKqbMZ DOMA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0p4YzJ/lUTbiaQvBDWsq+p14sqeZ58CQo1YDhBB0lrE=; b=V6dH0XaRx4INJ2lzH+Sbqfjz2TGB+XXR2maG+V05DrEXD1/pf9Ttm/1U/Rllr1/RyJ eP+swY4bHSrUpItp78ImuXPE3hF0b2diGMxJDMOj7ZnpNea6VliUMeVIwSkklJmtzDj9 SmbX9TIYWJfc5wK0Q+HOBWrAIfoVdwiA+SJNkM6y9ts2+GgfJ6oh8Tb7Q7BtFOj+1+MT +dFziI9GDxGvXdlAOTLrkwtBiLFYlp1lQ12wD/b16XswAHXSr93OXave2I398gEi+zVw wox714I6uzcrnWzY2BLNmdC3HA5HwbFgc07elfpS5tHkqHNt8BHeKpvdHNJklPqvKtg/ Sg+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lqs1cbFs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id mh7-20020a17090b4ac700b001e0a4778cecsi3851523pjb.110.2022.06.01.12.36.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 12:36:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lqs1cbFs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D08301B07AC; Wed, 1 Jun 2022 12:05:16 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235331AbiE3Ovi (ORCPT + 99 others); Mon, 30 May 2022 10:51:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242624AbiE3ObY (ORCPT ); Mon, 30 May 2022 10:31:24 -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 91D6E12DBC6; Mon, 30 May 2022 06:53:14 -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 6BF9E60F24; Mon, 30 May 2022 13:52:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2BCD5C3411C; Mon, 30 May 2022 13:52:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1653918774; bh=ejMD652Yw8v6FqVr0yyLm749VC0Rg0oqhwUlI6amkUE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lqs1cbFslqzO4j8spujayMga+0WL74JOtBEJbuDLolCwvkQoDvUBa9BpI3VKDHV06 oEKJDU0l2/JDUODGvIWrK5Y6xObD34qwF2meRtkdmoolFbKZMKDtYC5qDFbkskhL+r HdDkcHf5KwO+G7kF213bsg4f7Z74YrrIiLxFDuL+unGfTW31Xyf53c5tr4dDOvc4fI LA6yrysO5tGayCv0YXnDDSoZf7qVeJMAUVIMR1eCmAw7g0g+EgoZ2EXlMHXMjKPsSD E4sFQ9TXAL8Kl+cj7fcxKwfsa62QSKssPBKYJw6IcSi/w4FslGJKgztvdVu4V0J3St hfYoYwweRgihA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Corey Minyard , Haowen Bai , Sasha Levin , openipmi-developer@lists.sourceforge.net Subject: [PATCH AUTOSEL 4.9 17/24] ipmi:ssif: Check for NULL msg when handling events and messages Date: Mon, 30 May 2022 09:52:04 -0400 Message-Id: <20220530135211.1937674-17-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220530135211.1937674-1-sashal@kernel.org> References: <20220530135211.1937674-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 a4ef9a6bd367..45117728e735 100644 --- a/drivers/char/ipmi/ipmi_ssif.c +++ b/drivers/char/ipmi/ipmi_ssif.c @@ -812,6 +812,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); @@ -835,6 +843,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); @@ -857,6 +873,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