Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756548AbdCTSZX (ORCPT ); Mon, 20 Mar 2017 14:25:23 -0400 Received: from mail-oi0-f43.google.com ([209.85.218.43]:33717 "EHLO mail-oi0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756498AbdCTSZR (ORCPT ); Mon, 20 Mar 2017 14:25:17 -0400 MIME-Version: 1.0 In-Reply-To: <1489941516.2852.75.camel@decadent.org.uk> References: <20170316142906.685052998@linuxfoundation.org> <20170316142908.881234387@linuxfoundation.org> <1489941516.2852.75.camel@decadent.org.uk> From: Dan Williams Date: Mon, 20 Mar 2017 10:55:30 -0700 Message-ID: Subject: Re: [PATCH 4.4 33/35] nfit, libnvdimm: fix interleave set cookie calculation To: Ben Hutchings Cc: "stable@vger.kernel.org" , Greg Kroah-Hartman , "linux-kernel@vger.kernel.org" , Nicholas Moulin Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1455 Lines: 38 On Sun, Mar 19, 2017 at 9:38 AM, Ben Hutchings wrote: > On Thu, 2017-03-16 at 23:29 +0900, Greg Kroah-Hartman wrote: >> 4.4-stable review patch. If anyone has any objections, please let me know. >> >> ------------------ >> >> From: Dan Williams >> >> commit 86ef58a4e35e8fa66afb5898cf6dec6a3bb29f67 upstream. >> >> The interleave-set cookie is a sum that sanity checks the composition of >> an interleave set has not changed from when the namespace was initially >> created. The checksum is calculated by sorting the DIMMs by their >> location in the interleave-set. The comparison for the sort must be >> 64-bit wide, not byte-by-byte as performed by memcmp() in the broken >> case. > [...] >> --- a/drivers/acpi/nfit.c >> +++ b/drivers/acpi/nfit.c > [...] >> +static int cmp_map(const void *m0, const void *m1) >> +{ >> + const struct nfit_set_info_map *map0 = m0; >> + const struct nfit_set_info_map *map1 = m1; >> + >> + return map0->region_offset - map1->region_offset; >> +} > [...] > > This is returning an int, thus it's effectively doing a 32-bit > comparison and not the 64-bit comparison you say is needed. > > I think this function needs to do something like: > > return (map0->region_offset < map1->region_offset) ? -1 : > (map0->region_offset == map1->region_offset) ? 0 : 1; Yes, you're right. We could end up with unexpected sign changes. Good catch.