From patchwork Fri May 17 21:33:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Rees X-Patchwork-Id: 2584621 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id BD362DF215 for ; Fri, 17 May 2013 21:33:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756733Ab3EQVdL (ORCPT ); Fri, 17 May 2013 17:33:11 -0400 Received: from mout.perfora.net ([74.208.4.195]:61292 "EHLO mout.perfora.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756676Ab3EQVdK (ORCPT ); Fri, 17 May 2013 17:33:10 -0400 Received: from rees.org (108-204-28-189.lightspeed.anarmi.sbcglobal.net [108.204.28.189]) by mrelay.perfora.net (node=mrus4) with ESMTP (Nemesis) id 0MLewt-1UdB9i0Qlv-000XCe; Fri, 17 May 2013 17:33:03 -0400 From: Jim Rees To: Bruce Fields Cc: linux-nfs@vger.kernel.org Subject: [PATCH v2] nfsd: avoid undefined signed overflow Date: Fri, 17 May 2013 17:33:00 -0400 Message-Id: <1368826380-9864-1-git-send-email-rees@umich.edu> X-Mailer: git-send-email 1.8.2.3 X-Provags-ID: V02:K0:WCasmMKX03O/vxRS0ii0oczUoRYYAs5l/qPAOyU+pVQ AmwmaIpoTbiJ2v3bjyRq5IOeD+tuIeRCtSYmvqojoaOMjkdThb QOuBqBPpOlKsFetieDCiGcUHfXbnEDsVLuTxoGRE+BNrqAsYhQ VvSZw1gcqIUKn2pvO6AD94AiGLqyv5F4pVO0hn+jXaMAw/2ahu tYevZrvf6emBQ3rQsC099hqxtUP8SgQJOqGUX93Dhha/J04Dij 8pHzdBIqcowUYwtyHq0nFqvAjwyiBsYZWhezS11YpoZl7u+b7g AHfDvYeOaBiaMYuil0H4PER02p1CTT76/6fEuTIoQzXiLYwfVc BkxGzu/JKRTIjxVsglFX0/KOT0RlL9m+eIxSCRNPn Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org In C, signed integer overflow results in undefined behavior, but unsigned overflow wraps around. So do the subtraction first, then cast to signed. Suggested-by: Joakim Tjernlund Signed-off-by: Jim Rees --- fs/nfsd/nfs4state.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 316ec84..9850329 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -3427,7 +3427,7 @@ grace_disallows_io(struct net *net, struct inode *inode) /* Returns true iff a is later than b: */ static bool stateid_generation_after(stateid_t *a, stateid_t *b) { - return (s32)a->si_generation - (s32)b->si_generation > 0; + return (s32)(a->si_generation - b->si_generation) > 0; } static __be32 check_stateid_generation(stateid_t *in, stateid_t *ref, bool has_session)