From patchwork Sun Sep 14 21:22:22 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 4902401 Return-Path: X-Original-To: patchwork-cifs-client@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8AB0B9F2EC for ; Sun, 14 Sep 2014 21:19:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 01BA920220 for ; Sun, 14 Sep 2014 21:22:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2CA31201FB for ; Sun, 14 Sep 2014 21:22:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752781AbaINVWn (ORCPT ); Sun, 14 Sep 2014 17:22:43 -0400 Received: from mail-qc0-f179.google.com ([209.85.216.179]:33784 "EHLO mail-qc0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752753AbaINVWn (ORCPT ); Sun, 14 Sep 2014 17:22:43 -0400 Received: by mail-qc0-f179.google.com with SMTP id i17so3163342qcy.24 for ; Sun, 14 Sep 2014 14:22:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=t3AdO71k8vme5KTZfOk+XVJJwgkVucW9pracdPRUQDo=; b=iMphCFyTTz3+zKqiD81v1QHghDIk5c0s2aNosHWnQKM7tYDymXkJWlc55O1wfTYhNR r4IO/nZQc5ecXYM70rLhOIFu4PprAuYl663qbxZs5ka0CMP7m5GibGqefPvln5rZ2IYI VyXift739CufOqE6ahzeqM/rzmQGJyz9p/PZmFw1nfmOqXGlvnL2wBpglA4fEwPeTcp4 /Rz9jGUNSjbJKidkm/wcKbaYwBHNcfKWqfyZ+VArK5IDH7BiZYZUZ44H0UQlOh5Mg9jM rvMat0TFlhMEnl2QN6zwJ+9aUw9ed+CeCXsQ6EPVbXhBgw4yH0jOByMzzx3DXwidzIZY tedg== X-Received: by 10.140.43.70 with SMTP id d64mr15571097qga.74.1410729762276; Sun, 14 Sep 2014 14:22:42 -0700 (PDT) MIME-Version: 1.0 Received: by 10.140.32.116 with HTTP; Sun, 14 Sep 2014 14:22:22 -0700 (PDT) From: Steve French Date: Sun, 14 Sep 2014 16:22:22 -0500 Message-ID: Subject: [PATCH] [CIFS] Fix setting time before epoch (negative time values) To: "linux-cifs@vger.kernel.org" , linux-fsdevel Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP xfstest generic/258 sets the time on a file to a negative value (before 1970) which fails since do_div can not handle negative numbers. In addition 'normal' division of 64 bit values does not build on 32 bit arch so have to workaround this by special casing negative values in cifs_NTtimeToUnix Looks like fs/ntfs/time.h has the same bug Samba server also has a similar bug (being tracked by Samba bugzilla 7771), but Windows server works fine with this. Signed-off-by: Steve French --- fs/cifs/netmisc.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c index 6834b9c..3cb7403 100644 --- a/fs/cifs/netmisc.c +++ b/fs/cifs/netmisc.c @@ -925,11 +925,22 @@ cifs_NTtimeToUnix(__le64 ntutc) /* BB what about the timezone? BB */ /* Subtract the NTFS time offset, then convert to 1s intervals. */ - u64 t; + s64 t = le64_to_cpu(ntutc) - NTFS_TIME_OFFSET; + + /* + * Unfortunately can not use normal 64 bit division on 32 bit arch, but + * the alternative, do_div, does not work with negative numbers so have + * to special case them + */ + if (t < 0) { + t = -t; + ts.tv_nsec = -(do_div(t, 10000000) * 100); + ts.tv_sec = -t; + } else { + ts.tv_nsec = do_div(t, 10000000) * 100; + ts.tv_sec = t; + } - t = le64_to_cpu(ntutc) - NTFS_TIME_OFFSET; - ts.tv_nsec = do_div(t, 10000000) * 100; - ts.tv_sec = t; return ts; }