Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp2703555ybb; Sat, 30 Mar 2019 11:31:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqwr1DGudausVOJz/gDcXBXDymOI5OMItIitIdsW/qtXn1buUo6+whr8VfrC+52UdfiWa6PQ X-Received: by 2002:a17:902:2c83:: with SMTP id n3mr57218029plb.281.1553970668400; Sat, 30 Mar 2019 11:31:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553970668; cv=none; d=google.com; s=arc-20160816; b=vd/OeCLyagZ6ESsDDiCn2shdxF3pj3ALqBXQi4BB3nYpZ5iPSpLxy9Jz46ploNGu6S cSVi1IVoafvyCtnxwuoJ/JRGRJ+DwfW8N+6Ao2j1U29Od1sYWJvAIivyyEfd53IVp2zx /MtWR4euRE8jTWi1v77zeo2rB+tL5EXxeiwkb8phbg1KOQzfg79UmxK/a/+z/Ccbd2Bp 7x49ZD3TOr7vxM9XiXk8IT+vF4teWvG8oJZIfE4mGnQF4F0hplA+taERsz+zQM8W/zpm 9DsysFZsEXMSt0Wvsqit5+5WxvoTTMGuW87UVxYXpPOo3mHJxuj50K0tw2aAq36a0A0C PkTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=Q92E7vMhR72b13ilIGnUBU/3ZroPOzD9sO7tAwEn/eI=; b=XSMLMiZxB6sQsoulsk2ebzY5+LaAsC6lT8GfcZdwB0iRlURtntiiOl/3ApPh5X2N+w +0c9W4ZAfZnpiWI9MAM4Lpe4tE4jYWtV5BKOPcJdbXzI7qyeJIt2lKMfzB1XmU7LFhkx EgYot8jMuOZb93lWg63AoX5u6pQwHjvN8PK41diBLTHU4cqDzKbksb9DhsXFYz16PdO8 rVFfHexosxWLfnqqM8CpyDX1VewueYbN8/kYo0BVv7cVik5JHtyUydgbBqeUcGwLN0Cm i41LHJpzjdLKSa/Gukt9dR0bxV5sCWhN0/I6LvjbJ0/k+vN9FyLVis3n3Iuu2cVLg/qW Vdyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HxjGz47F; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cv17si1705015plb.380.2019.03.30.11.30.53; Sat, 30 Mar 2019 11:31:08 -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=@gmail.com header.s=20161025 header.b=HxjGz47F; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731023AbfC3SaL (ORCPT + 99 others); Sat, 30 Mar 2019 14:30:11 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:34682 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730675AbfC3SaK (ORCPT ); Sat, 30 Mar 2019 14:30:10 -0400 Received: by mail-lf1-f66.google.com with SMTP id y18so3574827lfe.1 for ; Sat, 30 Mar 2019 11:30:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=Q92E7vMhR72b13ilIGnUBU/3ZroPOzD9sO7tAwEn/eI=; b=HxjGz47FQpw1zfPZMzruKHtVibBw4NqLSBIK9dW/pAfisbeD0SMA2Qcs1hTQnTfcs8 /F+NyPvMa09pHFWW9I/p65zmGeqmqtXb2TgKAMpXBxfbLg/SkvbxQtDVw1AFfG5cChmB jqf6/gw/A/YGvkZTdyXsV4Y9G7wXR2xYwnq27uOmuJ4orirdXJ7UvuRotAjKilnwb4gE WUzbCnwS6k7iMu5j9RbnlHOpppxQCzoXyzgJPnigce8OIqgTEmIef4jOaxYXutgtLuti Q9RlW/epZ5XipgrNiG3bT/u9Ch/ACCo86sm2yL/ZR+EmMOENudNmMrQ9STJvdK90x3xJ +6Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Q92E7vMhR72b13ilIGnUBU/3ZroPOzD9sO7tAwEn/eI=; b=D+CpCH4WQTfQQ4d9qi011W8pD2ZBipAwxc5UXFJgP1s/U36kI/vHwui2sfVA6YGIDQ sir/pjKilev6wOY0t8u5aqgBXP5VLLguBBtZ5H2J7EfPpLwGU0diVrVqLLy4fN2cZH9a iU0smE8iPcHsYLfdpxh/Cm06pc4ATsqo7Prp5mNvxTFgV15WjYsOfR6d7ej3rNGOWArV AAhyHP7VFN7Na+24u+TdqjHXDf5dnsAkNSy0X5de3GC8cqS5TNVfwBPe/aEfeVHS9M8I I+Z917s6IbPEyw47jrhCpUheTbVU3/SC6PwBLkas34YCzg+le+UZEQrLa1p6P9j1xvOP 4zAA== X-Gm-Message-State: APjAAAWYhO43akfUr4HSwIdBJmmHJQA4aOLLmG/BPkww4mJVCtXtOVWl e5kKxnlGsZ5ufLwrZ/1BopI25cA1 X-Received: by 2002:ac2:4152:: with SMTP id c18mr8642885lfi.84.1553970608464; Sat, 30 Mar 2019 11:30:08 -0700 (PDT) Received: from localhost.localdomain (v902-731.aalto.fi. [130.233.10.238]) by smtp.gmail.com with ESMTPSA id o7sm1060058ljj.23.2019.03.30.11.30.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Mar 2019 11:30:07 -0700 (PDT) From: Ferdinand Blomqvist To: linux-kernel@vger.kernel.org Cc: Thomas Gleixner Subject: [RFC PATCH 0/7] rslib: RS decoder is severely broken Date: Sat, 30 Mar 2019 20:29:40 +0200 Message-Id: <20190330182947.8823-1-ferdinand.blomqvist@gmail.com> X-Mailer: git-send-email 2.17.2 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The Reed_Solomon library used in the kernel is based on Phil Karn's fec library. When playing with this library I found a couple of bugs. It turn out that all of these bugs, and some additional flaws, are present in rslib. The Reed-Solomon decoder has several bugs/flaws: - Decoding of shortened codes is broken. - The decoder sometimes fails silently, i.e. it announces success but returns a word that is not a codeword. - The return value of the decoder is incoherent with respect to how fixed erasures are counted. If the word to be decoded is a codeword, then the decoder always returns zero even if some erasures are given. On the other hand, if the word to be decoded contains errors, then the number of erasures is always included in the count of corrected symbols. So the decoder handles erasures without symbol corruption inconsistently. This inconsistency probably doesn't affect anyone using the decoder, but it is inconsistent with the documentation. - The error positions returned in eras_pos include all erasures, but the corrections are only set in the correction buffer if there actually is a symbol error. So if there are erasures without symbol corruption, then the correction buffer will contain errors (unless initialized to zero before calling the decoder) or some values will be unset (if the correction buffer is uninitialized). - Assumes that the syndromes provided by callers are in index form. This is simply undocumented. - When correcting data in-place the decoder does not correct errors in the parity. On the other hand, when returning the errors in correction buffers, errors in the parity are included. This series provides a module with tests for rslib and fixes all the bugs/flaws. I am not sure that the provided self tests are written in the 'right way'. I just looked at other self tests in lib and implemented something similar. The fixes are tested with the self tests. They should probably also be tested with drivers etc. that use rslib, but it is unclear to me how to do this. I looked a bit on two of the drivers that use rslib: drivers/mtd/nand/raw/cafe_nand.c drivers/mtd/nand/raw/diskonchip.c Both of them seem to do some additional error checking after calling decode_rs16. Maybe this is needed because of the bugs in the decoder? Ferdinand Blomqvist (7): rslib: Add tests for the encoder and decoder rslib: Fix decoding of shortened codes rslib: decode_rs: Fix length parameter check rslib: decode_rs: code cleanup rslib: Fix handling of of caller provided syndrome rslib: Update documentation rslib: Fix remaining decoder flaws lib/Kconfig.debug | 12 + lib/reed_solomon/Makefile | 2 +- lib/reed_solomon/decode_rs.c | 112 +++++-- lib/reed_solomon/reed_solomon.c | 12 +- lib/reed_solomon/test_rslib.c | 519 ++++++++++++++++++++++++++++++++ 5 files changed, 622 insertions(+), 35 deletions(-) create mode 100644 lib/reed_solomon/test_rslib.c -- 2.17.2