From patchwork Sat Jun 23 12:55:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengguang Xu X-Patchwork-Id: 10483615 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 24A91604D3 for ; Sat, 23 Jun 2018 12:55:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1167828D36 for ; Sat, 23 Jun 2018 12:55:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 045E428D4C; Sat, 23 Jun 2018 12:55:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 97CD728D36 for ; Sat, 23 Jun 2018 12:55:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751869AbeFWMzx (ORCPT ); Sat, 23 Jun 2018 08:55:53 -0400 Received: from mout.gmx.net ([212.227.17.20]:51841 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751787AbeFWMzw (ORCPT ); Sat, 23 Jun 2018 08:55:52 -0400 Received: from localhost.localdomain ([122.224.77.194]) by mail.gmx.com (mrgmx101 [212.227.17.174]) with ESMTPSA (Nemesis) id 0LtmK9-1gDzNM2Fyn-0117qk; Sat, 23 Jun 2018 14:55:46 +0200 From: Chengguang Xu To: ceph-devel@vger.kernel.org Cc: zyan@redhat.com, idryomov@gmail.com, Chengguang Xu Subject: [PATCH 1/3] ceph: add BUG_ON check to ceph_pagelist_encode_string() for safety Date: Sat, 23 Jun 2018 20:55:22 +0800 Message-Id: <20180623125524.29233-1-cgxu519@gmx.com> X-Mailer: git-send-email 2.17.1 X-Provags-ID: V03:K1:V4e13FOZVHRj4QTFNI3m5a83/smRqnQhOsIoO3kaDM+yO8TxyP+ W+SiGkKlTipFYg7eJjY+zGZ8ep1RUZZzFdoyc397w7N+SblYvnE4QRJe8pX4s+dLOxQZQsv JLUv2QynxOw9kXIUDQwJCVO0oZ+DEFjAzsPCk8MY0AtJgo+VOrRWPxbJXUGyNBWHzKYEAWX W1PBH6JZVATOMRK+E7Row== X-UI-Out-Filterresults: notjunk:1; V01:K0:325Hjb9wYZc=:vNCozqLF38kxWWFC/n1iMj YhfIFJxCbRbX5Q4iP2oHOmoumPfQPvGojoDYLdpdiWT2m30qkDp6sxUAI7XRSVebFFJsid1D5 PetBt/uBB432fhDDwcC4M4OiAibIzo2OU+SaGV3mpAxSYvv0z2D0/bV8vKWYbbdmOithNYh6p fRrh0x51oSSg00MfYzYcyZBsvCaV/QqLUUzJ45XGydKWyKyYexgim/bakIHLUbcJmcKD8Zs/y p3JXGxckkMF0NjOSuE0PxOZDeeSI1nc+os1WOz1fMpyS7SNtOZDd6fovpnf3/nt/sXTriUWHS qrNzl0z5vR63qEoWSOGXEYncfQsALWUS70+YPVkEz9XWTvYU+LouQDHAt8MZuW2/c5EWOeT4O nZvFemJ1kydDPfM2Q8iwCNNn/VvR3kL7luTm7AfnmxjYn65vtv7xw2w7JqYkyjzFJBxffKAIU beynM919+liuN0R15rbZOmy1rXmmpxffMV0g0X621wc/oK5u6qsCcGzSEiEpc7/icTsaejMic FVYilIPkZZVNiCH7YicZ7elB88zyE7XiLCp4Rm1R59sp5qh8nLCtU0yJ0PtDgucKEXjBrT4/m G/G5ndG6cBymu6lbZj4WYK9uCT32THf4pseQdREduLNbWVHl7nZKK/hKwfXiN9/bZbb8ZPqnA c7U2RAvORKIRqI1a3LP/UcnwVSshmUnWokM4S6NDwD/EMgJnFQFsR3wVzRTh3DhMDthzmn2w2 b+yafong43OV53waA600FiLyFPnJb2j62Lf4VydDh5ULV7E7OaXY1lvdC/E= Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP ceph_pagelist_encode_string() should only handle string which is not longer than U32_MAX. However, the type size_t in 64bit environment will be 64bit unsigned long. So add a BUG_ON check just for safety. Signed-off-by: Chengguang Xu --- include/linux/ceph/pagelist.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/linux/ceph/pagelist.h b/include/linux/ceph/pagelist.h index 7edcded07641..0120af5cd1d4 100644 --- a/include/linux/ceph/pagelist.h +++ b/include/linux/ceph/pagelist.h @@ -70,7 +70,10 @@ static inline int ceph_pagelist_encode_8(struct ceph_pagelist *pl, u8 v) static inline int ceph_pagelist_encode_string(struct ceph_pagelist *pl, char *s, size_t len) { - int ret = ceph_pagelist_encode_32(pl, len); + int ret; + + BUG_ON(len > U32_MAX); + ret = ceph_pagelist_encode_32(pl, len); if (ret) return ret; if (len)