From patchwork Sun Jul 30 02:20:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 108949 Delivered-To: patch@linaro.org Received: by 10.182.45.195 with SMTP id p3csp2174338obm; Sat, 29 Jul 2017 19:21:43 -0700 (PDT) X-Received: by 10.84.169.4 with SMTP id g4mr12223435plb.94.1501381303757; Sat, 29 Jul 2017 19:21:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501381303; cv=none; d=google.com; s=arc-20160816; b=i/gx3/8XGNjyd6ULw8s16G2iwveZsVWWyMqxRNWuaaJmz+G4sc4wTTgC65nbSc570d 0isGYqyhoac1AtiEl6CC/ZlDQY9z24V3FmVSF/yUjawDZw9LiNHHRAAUowKCZSexB6DD tOymjZfcI9d/iIf09/JZgHh7GE7Yh/dWwrVSmCaPirvd+mDikqdXm3o26AXWWj3c4LEz 3wK+pyj6hXs5iebgU5WP583rN2Pb2lbCn+NKNIFXiaEg9ZHvl6YIy9ZygugJKarCVawE RutA9OuGnklG2nOzL6zeBey60l/PehVFZT0N6WqzveKly0AFNc4NbwofxqhZKlsZ6tdI wrhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=IaJ/k4S/QrajatAbB0c97HkneSbffQexkM/25AN6RHA=; b=yzjpmsWDuxcbuiT6MIxjT++/HJEvEHQDRHABZqc+8Dllw36/Vp8ZK8+2aGpmIPEL1W LuifHtUodswP8wNscTva/bcjdzOivcoP82slEr+8ewU0FIS1LEeWmJ15jD8MCmeA9V3P kydvI43p7TkSjsClVqns2ChK8VnpqVtcOouYvR+djklEcCKvJjBj1OdnjrfIukGFkgyD f0PtaY9keTzzg0wlUZ0I6xFatHniNMYVZ/j+dIa6TTGPMfHvscnGSxWDur1ybdTzh5Tp 9o3XL7lonGlqY6sv37Lj3amimbdICAFTp4eko3797acFpsEF+EKdNx+fo7SmNsStzoVi VJ5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.b=QGn7ldv3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l12si10137578pgs.966.2017.07.29.19.21.42; Sat, 29 Jul 2017 19:21:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.b=QGn7ldv3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753724AbdG3CUg (ORCPT + 26 others); Sat, 29 Jul 2017 22:20:36 -0400 Received: from mail-oi0-f65.google.com ([209.85.218.65]:37188 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752698AbdG3CUf (ORCPT ); Sat, 29 Jul 2017 22:20:35 -0400 Received: by mail-oi0-f65.google.com with SMTP id j194so15565074oib.4 for ; Sat, 29 Jul 2017 19:20:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=IaJ/k4S/QrajatAbB0c97HkneSbffQexkM/25AN6RHA=; b=QGn7ldv3BNEw5tkVIOlzdmRN14Vwoj/+y7cGDm9t7hz6STwBNbsM3gGd5OdROTR5Yr RE1xnzCxtDb6RXriuuomT+ID6cNKgtryOQwsZjgfsMv6tI7QDWV7L6GWGqDv4Bq8buIT FzJMqzvoJutUE8maGx5MjXfbio3W7cexBFDDpCACPpu8dUl60JKhqt+7oAWO/8N+lt1N ZuAV9B8yXSlAKLwr8ehre/IqTdjHHf1ff9mMxm+Qk56WPVlxMYWjndajBEV6wU3tTmxx Z+dDK0kpS/CM7kdBPKaKR/S2SHjVUlhExkUr4EW2hJIe5c3wpyDcwVncPDHmPzfngpnI i9JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=IaJ/k4S/QrajatAbB0c97HkneSbffQexkM/25AN6RHA=; b=GIzuWirXvoZchkjWdokvH0qEgMl1w5trPcDF+h1+XCQ2bUI+NvLifx93lbAnKEFh/O U5wVZITkjciJ+9MuL5tFLsgmbUrlvDqTVP43gE0jI3QUTC0nzCgfj3nPsgIWB9Ewv2Ez ZrSlmxawp8Hvv2tN9YzF/yCROsB9vvqQcHoCU8gJn24vuU4ASKZI05a2nl4X0uOlvZdX ntZ0TUR1CYijqfAEK8vcr8Rc7b2g1toypKL6chfpYCeQ/MN2EcD4fjFBPxTX2rW7xcVv 47ziUowPkrhpMv48/f533DdvuXCoQEryprm4sas71lqdQo7DWdTPIdQRnmB189s2j71b aDDg== X-Gm-Message-State: AIVw111SHpscEM/5ElRWfJG2gFz7K6W/D7S/z75gCISpZ4E0/kglDFAl /MYpawb456upgQ== X-Received: by 10.202.48.5 with SMTP id w5mr10457515oiw.101.1501381234456; Sat, 29 Jul 2017 19:20:34 -0700 (PDT) Received: from serve.minyard.net ([47.184.154.34]) by smtp.gmail.com with ESMTPSA id e204sm22028746oia.45.2017.07.29.19.20.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Jul 2017 19:20:33 -0700 (PDT) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 2DA7D332; Sat, 29 Jul 2017 21:20:31 -0500 (CDT) Received: by t430.minyard.net (Postfix, from userid 1000) id 49068300A6A; Sat, 29 Jul 2017 21:20:30 -0500 (CDT) From: minyard@acm.org To: Weilong Chen Cc: openipmi-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org, Corey Minyard Subject: [PATCH] ipmi: fix unsigned long underflow Date: Sat, 29 Jul 2017 21:20:28 -0500 Message-Id: <1501381228-30958-1-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1501296161-74544-1-git-send-email-chenweilong@huawei.com> References: <1501296161-74544-1-git-send-email-chenweilong@huawei.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Corey Minyard When I set the timeout to a specific value such as 500ms, the timeout event will not happen in time due to the overflow in function check_msg_timeout: ... ent->timeout -= timeout_period; if (ent->timeout > 0) return; ... The type of timeout_period is long, but ent->timeout is unsigned long. This patch makes the type consistent. Reported-by: Weilong Chen Signed-off-by: Corey Minyard --- I like to keep things consistent (though I obviously messed up here) and keep variables that should be positive unsigned. But you are right, there is a bug here and some inconsistency. This patch changes timeout_period to be unsigned and fixes the check. Can you try this out? drivers/char/ipmi/ipmi_msghandler.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) -- 2.7.4 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c index 810b138..c82d9fd 100644 --- a/drivers/char/ipmi/ipmi_msghandler.c +++ b/drivers/char/ipmi/ipmi_msghandler.c @@ -4030,7 +4030,8 @@ smi_from_recv_msg(ipmi_smi_t intf, struct ipmi_recv_msg *recv_msg, } static void check_msg_timeout(ipmi_smi_t intf, struct seq_table *ent, - struct list_head *timeouts, long timeout_period, + struct list_head *timeouts, + unsigned long timeout_period, int slot, unsigned long *flags, unsigned int *waiting_msgs) { @@ -4043,8 +4044,8 @@ static void check_msg_timeout(ipmi_smi_t intf, struct seq_table *ent, if (!ent->inuse) return; - ent->timeout -= timeout_period; - if (ent->timeout > 0) { + if (timeout_period < ent->timeout) { + ent->timeout -= timeout_period; (*waiting_msgs)++; return; } @@ -4110,7 +4111,8 @@ static void check_msg_timeout(ipmi_smi_t intf, struct seq_table *ent, } } -static unsigned int ipmi_timeout_handler(ipmi_smi_t intf, long timeout_period) +static unsigned int ipmi_timeout_handler(ipmi_smi_t intf, + unsigned long timeout_period) { struct list_head timeouts; struct ipmi_recv_msg *msg, *msg2;