Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2250970imm; Thu, 18 Oct 2018 11:24:38 -0700 (PDT) X-Google-Smtp-Source: ACcGV60skAjLVDoCQmUUb8NxBQYExN00+Wcyn/x88n7HNVyq6c0gzDE1Bk54IddMtv8cqB5ztTcK X-Received: by 2002:a62:41d6:: with SMTP id g83-v6mr31338270pfd.44.1539887078705; Thu, 18 Oct 2018 11:24:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539887078; cv=none; d=google.com; s=arc-20160816; b=ymklJ4DSh0d858I1TCCJs9TRyMwMmzM/0mKSKiTgLBMihIhDNfios89IDF5JyvJvTT CLYBwiufKEECYtFAijRylVbAw68Ry5rAcCUDZ0eo6aBS7sv+H5nFarT8GlcXoLkUEenC dFDI+UM6Du7OO5XQjdPXHhFwmwIbO2K4tGAS+nFAt50df0JACu5ZLCxrGngC0BsJ3OV2 Jtrq6NFxwF9tK+YL+saCx1Rvr5ilAvDBgPfHTgAo5gbXGmbVAOBbr+LKg7d94cXoLEnG VZcISTY3KWNls74O0lbrz2l/OW08EodjuwRs0aIoOiQ1qzzKNs4S7C7bfQh2mN0+4c6O FlYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0pJDqlbZ3Vr4rQOje6pRAFMCoaQZIi26IcdIfMBLHxw=; b=sVYg5J+vkNjfV3wy5tO/xRjcMnQok+E6bC1fB4PYqvb8d/6I/FEYWni1kRZ6At7LKi +iDtLIysixGl4dUNdpwFPJPrVNsIAiA9Kmsw/TtgRt2RUmSm/RdGjyrhdllyAyD4kcMo 8LHCyhTTuASmsguYiDYxEevZvBysEHlOYtYmH6nca5DbxFr96al3eTEkt5ivekYhyAj0 VunteQW8Fp+dlshaJ1EjKZWTAOP2Y5fByIQF6u58qHVXvKUCoGjWpGgwOHRwZIy+WbGv qWXz9GRXzeaf5EP8jZ/Q7CJFCzY2ocIJntKaqW98/Qw6xeSbZGukhyv2qw+mE6FxlTHV Q5fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hIB+jM29; 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 o12-v6si23199576pfh.9.2018.10.18.11.24.22; Thu, 18 Oct 2018 11:24:38 -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=pass header.i=@kernel.org header.s=default header.b=hIB+jM29; 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 S1729012AbeJSCAU (ORCPT + 99 others); Thu, 18 Oct 2018 22:00:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:47960 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726650AbeJSCAT (ORCPT ); Thu, 18 Oct 2018 22:00:19 -0400 Received: from localhost (ip-213-127-77-176.ip.prioritytelecom.net [213.127.77.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BE120204FD; Thu, 18 Oct 2018 17:58:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539885494; bh=aiWHOsR2xNDocpmVRXgOK1SbWl9sJkagVJe5Oi5KYj8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hIB+jM29G9Apuum6z9CBvlSIWuJDhRA5MUDId+Z3s8JiLQm3tSCbtl2mUDfBx5k7Q DAkVC8m5XiKzbwzibwQP0x3vz02FOMLTDw6Ql86jMlLnHAwLtfd/6GrjC3xj0fIgRC rnM/pS07Fp7NRPwxjrKF/e5MQ8ZKyamqTPr9vNoA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jozef Balga , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 4.18 04/53] media: af9035: prevent buffer overflow on write Date: Thu, 18 Oct 2018 19:53:57 +0200 Message-Id: <20181018175417.327286614@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181018175416.561567978@linuxfoundation.org> References: <20181018175416.561567978@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jozef Balga [ Upstream commit 312f73b648626a0526a3aceebb0a3192aaba05ce ] When less than 3 bytes are written to the device, memcpy is called with negative array size which leads to buffer overflow and kernel panic. This patch adds a condition and returns -EOPNOTSUPP instead. Fixes bugzilla issue 64871 [mchehab+samsung@kernel.org: fix a merge conflict and changed the condition to match the patch's comment, e. g. len == 3 could also be valid] Signed-off-by: Jozef Balga Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/media/usb/dvb-usb-v2/af9035.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/drivers/media/usb/dvb-usb-v2/af9035.c +++ b/drivers/media/usb/dvb-usb-v2/af9035.c @@ -402,8 +402,10 @@ static int af9035_i2c_master_xfer(struct if (msg[0].addr == state->af9033_i2c_addr[1]) reg |= 0x100000; - ret = af9035_wr_regs(d, reg, &msg[0].buf[3], - msg[0].len - 3); + ret = (msg[0].len >= 3) ? af9035_wr_regs(d, reg, + &msg[0].buf[3], + msg[0].len - 3) + : -EOPNOTSUPP; } else { /* I2C write */ u8 buf[MAX_XFER_SIZE];