Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2512890imm; Thu, 7 Jun 2018 11:56:13 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIMZl2W4F79mEgytjLEWIS/eUPXG7cWGbuzG/VJc5NQuI9xBzCI8xENXgCVdP5i25g8n+VQ X-Received: by 2002:a17:902:41:: with SMTP id 59-v6mr3220439pla.345.1528397773449; Thu, 07 Jun 2018 11:56:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528397773; cv=none; d=google.com; s=arc-20160816; b=Ii0Of7lsOGAcjO7ZjZsyQC86189D9NM6gGlu+JJhWsNuNNVlZtIOUrAQui1zjmo1Dw njV9GGEI8ff8eJ7KW4vLcsJXCB13o5wOatxR66UplwquOaj9HSuUshj1wZZ9U196OzfW qBYUQd20qvDKmxeFPPnkeEO4wlreRmhRKU/FpaY19GKyFmXDn/8cWWezLeVvNpVVOxIO 0CZzGJUAbkf5Lq1PvYj87Xf0iI1iUesYzr6lZpPgA0+xvw61EtbFfV6x9yok160achmq I4pHt70wZAv6vNALVTRvb81HfxHSb/AEpLpiJY0E2dODBiCFT9wryfRx0CI5JmHA6rBF NZUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=Xb7bnDSIJotgln3+MGUymAVHtqVprilBgH9jF8SGbdg=; b=xV03+Opyvv17zOb8MEzQ//EEdO+/x26Q1eqlCdhBu9A1/qwQO7ePdIjEprvzRvNXWI rQ2uUUypw0iqusYCIuhhbPTgYd2RNWliC2OK/1tJF5z9pk0B7rBOclegpzRKWpCr1+zI I9KLz/ns/NVpTdIRNhc8HAFTkCNHxyvyYh6ZZIUS+Tw3gi9fNIRuJOCeEunCpkNLiVwu CeS2m25kVUF+m+lGmN6er/adY1ce4ewfnJIrYCNjM+cDv455Xj6LbZRTdn9xQY/4CEhB cqfO7Y2E7QKhlme1Bw5GKH8n5kvKqo6CtouYh0PywHyWEPmwLT+FnEK9/6uomRyC7tQY RRYQ== ARC-Authentication-Results: i=1; mx.google.com; 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 f9-v6si2632151pgt.128.2018.06.07.11.55.59; Thu, 07 Jun 2018 11:56:13 -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; 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 S934649AbeFGP6E (ORCPT + 99 others); Thu, 7 Jun 2018 11:58:04 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:39334 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933050AbeFGOJH (ORCPT ); Thu, 7 Jun 2018 10:09:07 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvb7-0005Zx-K8; Thu, 07 Jun 2018 15:09:05 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvb3-0002uh-Hp; Thu, 07 Jun 2018 15:09:01 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Dan Carpenter" , "Greg Kroah-Hartman" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 150/410] staging: rts5208: Fix "seg_no" calculation in reset_ms_card() In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Dan Carpenter commit 7f7aeea7cf30368b9fdb86dcc9d2c8a3ebc65dfb upstream. I get some static checker warnings like this: drivers/staging/rts5208/ms.c:2607 ms_build_l2p_tbl() error: buffer underflow 'ms_card->segment' (-1)-16 The problem is that we memset "ms_card" to zero at the start of the reset_ms_card() function. That means that when we try to calculate "ms_card->total_block / 512 - 1" then it's just always -1. The fix is to calculate "seg_no" before doing the memset(). This is a static checker fix, and I am not able to test it. My theory is that reset_ms_card() gets very little testing which is why this bug exists. Fixes: fa590c222fba ("staging: rts5208: add support for rts5208 and rts5288") Signed-off-by: Dan Carpenter Signed-off-by: Greg Kroah-Hartman [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- drivers/staging/rts5208/ms.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/drivers/staging/rts5208/ms.c +++ b/drivers/staging/rts5208/ms.c @@ -2397,6 +2397,7 @@ BUILD_FAIL: int reset_ms_card(struct rtsx_chip *chip) { struct ms_info *ms_card = &(chip->ms_card); + int seg_no = ms_card->total_block / 512 - 1; int retval; memset(ms_card, 0, sizeof(struct ms_info)); @@ -2430,7 +2431,7 @@ int reset_ms_card(struct rtsx_chip *chip /* Build table for the last segment, * to check if L2P table block exists, erasing it */ - retval = ms_build_l2p_tbl(chip, ms_card->total_block / 512 - 1); + retval = ms_build_l2p_tbl(chip, seg_no); if (retval != STATUS_SUCCESS) TRACE_RET(chip, STATUS_FAIL); }