Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp445097iog; Mon, 13 Jun 2022 06:08:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyD5eKflxaNhnVmzl5hchBwYMuaEs4huKI2DYWTURrbgczQKqPGPUrQlNyXrKrS+Z8k39Xh X-Received: by 2002:a17:902:f541:b0:163:f64a:6127 with SMTP id h1-20020a170902f54100b00163f64a6127mr57840209plf.134.1655125592691; Mon, 13 Jun 2022 06:06:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655125592; cv=none; d=google.com; s=arc-20160816; b=BIURji6aO05GCwJHFgIhIhNVRSKWmnm83u3rKYGDwPNH7sRwg6sLxWOseBs1928kWK pga22ORFhL/0dlXdiXWDSJdQZO/vzR2OcjKMwZbht/7QvWyFpzELxy+PQaBKfY/TV4e+ PCxX6JrIf0hkKGb8C5jNUD1zOOC4l0htYyyAFlAq2/L6R5gnh3cKxfixEzYmOLGQboyS ZbkzxO/uMtry1/WGUSOAFh+sW80fZhAX5bP0FeoOF31f520yOUXQ/D8luMMQ2lbsHZvo pStmSzwinn+6f8ypRolInaiQeHSbjDeI5TIdP6WVmlrpBSAelPpLN4/adXc1AFeGCKB/ NprQ== 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=1csj+gDHdcIvPnF7RGdl/vO+eM7K7a31rN+URSA8TqI=; b=UevcCKyOCPETP96aaWUOkeKYT4E4RC64863W+rlw/slua30pWTKShjIHgSouJX+Ykb zMuJZqqlOhZDHb0ThzkOfZ2n2ZXtV38wi+jHVcDI0TqUbm14KFERPSGQHj0x/h9e3ABe nKbRCUcFq0Kh8j+peQh6eTBvHdxR24Ir5hM+YeJpvmUsRfx8emR7tXcLoJiWHk8wDPZW CemN/hMDJmmT8L9YUiodS7YBUcSl7DmLxMy9X1E9nuQE4xJnEmquuiGlXFJAiy67GlJy BAxMuPk5lOFvCPtTWtfGzflA4lmQsx0Y3MGQCnmNznb+JxmOAkkTDKkT/0ye1rD4ecFA P91w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cplE2j5j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l17-20020a056a00141100b0051c2af24938si10756706pfu.190.2022.06.13.06.06.07; Mon, 13 Jun 2022 06:06:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cplE2j5j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351241AbiFMLDr (ORCPT + 99 others); Mon, 13 Jun 2022 07:03:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350689AbiFMKzE (ORCPT ); Mon, 13 Jun 2022 06:55:04 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5580324BE5; Mon, 13 Jun 2022 03:31:51 -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 5E13F60FC9; Mon, 13 Jun 2022 10:31:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04EC3C34114; Mon, 13 Jun 2022 10:31:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655116309; bh=qhBdDSP/FzA3KPGOb2WnzGbQS+zoac+5ULvYh7qmlTU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cplE2j5jRE1hZEyCIrnj22Sixdk11eDSk4DJY0h+WUkTz5BipseiTgxkHD4r6tk3C y33u77lTOY40m1dk3SaQmHILBjfloMsQwHvp0BNdhSyBrkj2+aVA2+q1boO4TefCaz 2dPnyWd0MaQIR7lIfFldllKBFB7uR18pKnd2pMfw= 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.4 047/411] ipmi:ssif: Check for NULL msg when handling events and messages Date: Mon, 13 Jun 2022 12:05:20 +0200 Message-Id: <20220613094929.921771780@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094928.482772422@linuxfoundation.org> References: <20220613094928.482772422@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=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 bb42a1c92cae..60fb6c62f224 100644 --- a/drivers/char/ipmi/ipmi_ssif.c +++ b/drivers/char/ipmi/ipmi_ssif.c @@ -845,6 +845,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); @@ -869,6 +877,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); @@ -892,6 +908,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