From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.9 required=3.0 tests=DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6DB3C28CF6 for ; Wed, 1 Aug 2018 16:28:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8C7A620862 for ; Wed, 1 Aug 2018 16:28:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="w82Zei04" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8C7A620862 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390223AbeHASPB (ORCPT ); Wed, 1 Aug 2018 14:15:01 -0400 Received: from merlin.infradead.org ([205.233.59.134]:46826 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389980AbeHASPB (ORCPT ); Wed, 1 Aug 2018 14:15:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=u0jgE0H2AfGcsXZXYGsMnHOrHslIjgpdwTv+8jG7QXM=; b=w82Zei04qsKQOcQBoq+iDgmVWU Q7g/3lRripX5TUK+gB2lI02RLL228r7czGh93sev8LVBfa6AM0eQGGwRIcOxMhKlFLU0ZC/88q2S7 M0vlG9vdYTGyLEbsALL5EehAaX9gJo1eDJ8NEitTlOPwfk+QfFgFpB6TFWR8IFO+nvvUE7wf0oO4R crhjB3o++WZXLMIlfdYOCvH1HUZqO1q7T2hTI00eE2uXjbXXAwjQDQtph9y7YYFzP1D2rBr2S01dh +lzT3+jMxxyAWblWDvY52SQUJrIdA/BJOI7NM5s9rp6xr4Nhhe6si7b2PTL0IV2HStVNIKHauQsWj 2unLnUkA==; Received: from static-50-53-52-16.bvtn.or.frontiernet.net ([50.53.52.16] helo=midway.dunlab) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fktzA-0007Kz-6s; Wed, 01 Aug 2018 16:28:28 +0000 Subject: Re: [PATCH v3 1/3] overflow.h: Add arithmetic shift helper To: Kees Cook , Rasmus Villemoes Cc: Jason Gunthorpe , Leon Romanovsky , Jason Gunthorpe , Leon Romanovsky , Bart Van Assche , Doug Ledford , Dan Carpenter , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org References: <20180801060947.16670-1-keescook@chromium.org> <20180801060947.16670-2-keescook@chromium.org> From: Randy Dunlap Message-ID: <0568f73f-c1ff-1e9d-8ef9-04c46eb13d6e@infradead.org> Date: Wed, 1 Aug 2018 09:28:25 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20180801060947.16670-2-keescook@chromium.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/31/2018 11:09 PM, Kees Cook wrote: > From: Jason Gunthorpe > > Add shift_overflow() helper to assist driver authors in ensuring that > shift operations don't cause overflows or other odd conditions. > > Signed-off-by: Jason Gunthorpe > Signed-off-by: Leon Romanovsky > [kees: tweaked comments and commit log, dropped unneeded assignment] > Signed-off-by: Kees Cook > --- > include/linux/overflow.h | 31 +++++++++++++++++++++++++++++++ > 1 file changed, 31 insertions(+) > > diff --git a/include/linux/overflow.h b/include/linux/overflow.h > index 8712ff70995f..69fc366ce865 100644 > --- a/include/linux/overflow.h > +++ b/include/linux/overflow.h > @@ -202,6 +202,37 @@ > > #endif /* COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW */ > > +/** check_shift_overflow() - Calculate a left-shifted value and check overflow > + * > + * @a: Value to be shifted > + * @b: How many bits left to shift > + * @d: Pointer to where to store the result > + * > + * Computes *@d = (@a << @s) > + * missed @b [again] -- ~Randy