From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-sn1nam02on0135.outbound.protection.outlook.com ([104.47.36.135]:3040 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932823AbeDIAhq (ORCPT ); Sun, 8 Apr 2018 20:37:46 -0400 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Thiago Jung Bauermann , Michael Ellerman , Sasha Levin Subject: [PATCH AUTOSEL for 4.4 098/162] powerpc/perf/hv-24x7: Fix off-by-one error in request_buffer check Date: Mon, 9 Apr 2018 00:28:56 +0000 Message-ID: <20180409002738.163941-98-alexander.levin@microsoft.com> References: <20180409002738.163941-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002738.163941-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Thiago Jung Bauermann [ Upstream commit 36c8fb2c616d9373758b155d9723774353067a87 ] request_buffer can hold 254 requests, so if it already has that number of entries we can't add a new one. Also, define constant to show where the number comes from. Fixes: e3ee15dc5d19 ("powerpc/perf/hv-24x7: Define add_event_to_24x7_reques= t()") Reviewed-by: Sukadev Bhattiprolu Signed-off-by: Thiago Jung Bauermann Signed-off-by: Michael Ellerman Signed-off-by: Sasha Levin --- arch/powerpc/perf/hv-24x7.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/perf/hv-24x7.c b/arch/powerpc/perf/hv-24x7.c index e267f4c3e51d..8e80882d8f6d 100644 --- a/arch/powerpc/perf/hv-24x7.c +++ b/arch/powerpc/perf/hv-24x7.c @@ -160,6 +160,10 @@ DEFINE_PER_CPU(struct hv_24x7_hw, hv_24x7_hw); DEFINE_PER_CPU(char, hv_24x7_reqb[H24x7_DATA_BUFFER_SIZE]) __aligned(4096)= ; DEFINE_PER_CPU(char, hv_24x7_resb[H24x7_DATA_BUFFER_SIZE]) __aligned(4096)= ; =20 +#define MAX_NUM_REQUESTS ((H24x7_DATA_BUFFER_SIZE - \ + sizeof(struct hv_24x7_request_buffer)) \ + / sizeof(struct hv_24x7_request)) + static char *event_name(struct hv_24x7_event_data *ev, int *len) { *len =3D be16_to_cpu(ev->event_name_len) - 2; @@ -1083,7 +1087,7 @@ static int add_event_to_24x7_request(struct perf_even= t *event, int i; struct hv_24x7_request *req; =20 - if (request_buffer->num_requests > 254) { + if (request_buffer->num_requests >=3D MAX_NUM_REQUESTS) { pr_devel("Too many requests for 24x7 HCALL %d\n", request_buffer->num_requests); return -EINVAL; --=20 2.15.1