From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-f196.google.com ([209.85.210.196]:34184 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732141AbeGaOm5 (ORCPT ); Tue, 31 Jul 2018 10:42:57 -0400 Received: by mail-pf1-f196.google.com with SMTP id k19-v6so6080869pfi.1 for ; Tue, 31 Jul 2018 06:02:43 -0700 (PDT) From: Amit Pundir To: Greg KH , Stable Cc: Michael Mera , Doug Ledford Subject: [PATCH for-4.9.y] IB/ocrdma: fix out of bounds access to local buffer Date: Tue, 31 Jul 2018 18:32:22 +0530 Message-Id: <1533042142-8681-6-git-send-email-amit.pundir@linaro.org> In-Reply-To: <1533042142-8681-1-git-send-email-amit.pundir@linaro.org> References: <1533042142-8681-1-git-send-email-amit.pundir@linaro.org> Sender: stable-owner@vger.kernel.org List-ID: From: Michael Mera commit 062d0f22a30c39840ea49b72cfcfc1aa4cc538fa upstream. In write to debugfs file 'resource_stats' the local buffer 'tmp_str' is written at index 'count-1' where 'count' is the size of the write, so potentially 0. This patch filters odd values for the write size/position to avoid this type of problem. Signed-off-by: Michael Mera Reviewed-by: Leon Romanovsky Signed-off-by: Doug Ledford Signed-off-by: Amit Pundir --- Please cherry-pick it on 4.4.y as well. Not applicable for 3.18.y drivers/infiniband/hw/ocrdma/ocrdma_stats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_stats.c b/drivers/infiniband/hw/ocrdma/ocrdma_stats.c index 265943069b35..84349d976162 100644 --- a/drivers/infiniband/hw/ocrdma/ocrdma_stats.c +++ b/drivers/infiniband/hw/ocrdma/ocrdma_stats.c @@ -645,7 +645,7 @@ static ssize_t ocrdma_dbgfs_ops_write(struct file *filp, struct ocrdma_stats *pstats = filp->private_data; struct ocrdma_dev *dev = pstats->dev; - if (count > 32) + if (*ppos != 0 || count == 0 || count > sizeof(tmp_str)) goto err; if (copy_from_user(tmp_str, buffer, count)) -- 2.7.4