Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3523208rwb; Tue, 20 Sep 2022 00:26:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4FJWijlUSL1kDTfqerc34oGb3i+3Yfuhu0ViA31Kt12nbCoZIeuMjpRXJcm/Xq6clEIv2W X-Received: by 2002:a17:907:2e02:b0:77c:5020:b8ef with SMTP id ig2-20020a1709072e0200b0077c5020b8efmr15613114ejc.299.1663658788760; Tue, 20 Sep 2022 00:26:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663658788; cv=none; d=google.com; s=arc-20160816; b=E4YFlGunVEQhTufq/z8ZhUe/rj7eKx2gaebANqG/tZb/16hY+Ol+gGiq5uWxs43D37 pMA18t1OSHE9H1zgy/skf+lMNO78eSKv/txo24UleEQkGzibXfjsWX4+JOwSTFNcvPmQ 4OBPuPScCpLCb+7+8VzwrWNJ7dzjCHRZ75iaRme9s7g+1w24bDRZ1xRXtozANqzZqBSO U7TQPhYa3ge5jaDQcqtwnFElfkTZTYLB185tJSFKvzsjy660l1kBvoup2/K3Zhnpe4ra Li+HOZxhrleflcgwpDvWe/E6BO5YYFEZtZUBYMGFK7O7eg98WpgBuHLIDHdWIPRzafsE YJ0g== 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=U3gB5qFomBkj8LnmPk51r5hA0bTnvyrzZjuSaxWqPDA=; b=LWPXl1GFmV1J5SzL8QpL62fkJBw9or3kMWX00QiOhTRf+9FhDTFfJz/t8Kb3bRnj4a XBITz1dA2wMh/wO0lSmtMsdfAXIyIjkPMIMlT90J5OWaffMP63/W2QLMnQPg4w41HDEd kfVVQDWv291jmTMjzpQzyFpzRHvSJmYPpQiScE+dn7xZEvF2tP0aka98FCymkCuDfsrf J141C5cptxj2BBtJMMTUfTKsKaU8cem8bbAlMEwu0ZpZqC8/ojTWE9Wq7o2kMI3XN9Ql Fo/g2spnKOdK6rPz2zUIY2+VC4Xyq3WjF+b/47s048nVKlBd2pCFrXQxSX/G/GxieZUP 62DQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gW+oOuCl; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l19-20020a170906795300b007804b5a2c48si666023ejo.521.2022.09.20.00.26.02; Tue, 20 Sep 2022 00:26:28 -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=@intel.com header.s=Intel header.b=gW+oOuCl; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230488AbiITGs5 (ORCPT + 99 others); Tue, 20 Sep 2022 02:48:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230320AbiITGsy (ORCPT ); Tue, 20 Sep 2022 02:48:54 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B14D5E540 for ; Mon, 19 Sep 2022 23:48:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1663656534; x=1695192534; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RGdm1aXssN9TFvb1NrVDWI/D7fOta/uR4tLNgHnBB94=; b=gW+oOuCliVebTJ3v1YjDCWY1ptu1sWYceFk6FlXjH+e5rL9tqJks59mV ALknc40nbX7AQ4Px+bYMonyqXwLTurvE19ymqgI0MLHukwmOwrn39rQEk +q9sKxkjPnj1rHAUlYHRE4l+AYp/3mEhrVSdE6gcpF/ta1lurTRV2ce89 GDXyGeB/k/GqaSPoqY7j7yAGkywiGU7iP29lhp38vWFufXSPP7nXt/Gzi oScpyTiG0Y6Nns/2yP4zLqaj8b8XCOdBZDE3KYVBmcQqo1YXG4iRUBaeU uHMAiVSCBMcKcQQbbsE0O5omyqu3oPEBL6hA5sYnlVh9grtc1tFNuvGiA w==; X-IronPort-AV: E=McAfee;i="6500,9779,10475"; a="363573553" X-IronPort-AV: E=Sophos;i="5.93,329,1654585200"; d="scan'208";a="363573553" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2022 23:48:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,329,1654585200"; d="scan'208";a="681172664" Received: from linux-pnp-server-13.sh.intel.com ([10.239.176.176]) by fmsmga008.fm.intel.com with ESMTP; 19 Sep 2022 23:48:49 -0700 From: Jiebin Sun To: akpm@linux-foundation.org, vasily.averin@linux.dev, shakeelb@google.com, dennis@kernel.org, tj@kernel.org, cl@linux.com, ebiederm@xmission.com, legion@kernel.org, manfred@colorfullife.com, alexander.mikhalitsyn@virtuozzo.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: tim.c.chen@intel.com, feng.tang@intel.com, ying.huang@intel.com, tianyou.li@intel.com, wangyang.guo@intel.com, jiebin.sun@intel.com, Manfred Spraul , Tim Chen Subject: [PATCH] ipc/msg: avoid negative value by overflow in msginfo Date: Tue, 20 Sep 2022 23:08:09 +0800 Message-Id: <20220920150809.4014944-1-jiebin.sun@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <8d74a7d4-b80f-2a0f-ee95-243bdbd51ccd@colorfullife.com> References: <8d74a7d4-b80f-2a0f-ee95-243bdbd51ccd@colorfullife.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_06_12, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE 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 The 32-bit value in msginfo struct could be negative if we get it from signed 64-bit. Clamping it to INT_MAX helps to avoid the negative value by overflow. Signed-off-by: Jiebin Sun Reviewed-by: Manfred Spraul Reviewed-by: Tim Chen --- ipc/msg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ipc/msg.c b/ipc/msg.c index f2bb4c193ecf..65f437e28c9b 100644 --- a/ipc/msg.c +++ b/ipc/msg.c @@ -501,8 +501,8 @@ static int msgctl_info(struct ipc_namespace *ns, int msqid, max_idx = ipc_get_maxidx(&msg_ids(ns)); up_read(&msg_ids(ns).rwsem); if (cmd == MSG_INFO) { - msginfo->msgmap = percpu_counter_sum(&ns->percpu_msg_hdrs); - msginfo->msgtql = percpu_counter_sum(&ns->percpu_msg_bytes); + msginfo->msgmap = min(percpu_counter_sum(&ns->percpu_msg_hdrs), INT_MAX); + msginfo->msgtql = min(percpu_counter_sum(&ns->percpu_msg_bytes), INT_MAX); } else { msginfo->msgmap = MSGMAP; msginfo->msgpool = MSGPOOL; -- 2.31.1