Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1096291pxj; Sat, 15 May 2021 03:51:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfblUKXVb65Yeo5ktXL1LGZVXOiYhDIJTPRpOJnFnaaOzL2054T28JRSGPTeiohaDyuqih X-Received: by 2002:a6b:c981:: with SMTP id z123mr36916969iof.6.1621075897864; Sat, 15 May 2021 03:51:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621075897; cv=none; d=google.com; s=arc-20160816; b=EvgO5UzWlWGmqk/MG4GqryakYXZ817YauyG/pj3ixFFNlm4zX3MlVPxJWLgD6o3qIA 9TuXpYiiXnVcLNMD+0nekHqT26ExW3FGDoGzwi+u9VAtc94L2z7mB0bHaFRxIcImhwSb YzLO28aitU9jsKS2lW1R5204h1VrTAcqnr/xKjTcX/dC53aDoDRCCpvq2V3vJ6hYeaiZ m0hypuQBgR4kR/ztYdOR8c4QDFp3rFFmiWP7sUzozs6v3E9gW8HBzxcAVDtUjDyFG0wA cqe7N0/tvxRd3vBUhC22KbcEeX5ajE1IF21gfOyW0bjOXo5wdesxBnL6mwI6YvyWnlIf RIVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=rtc7bh6SLsClbxhlJjiKXW4/UoDoYGS7vk/xkHqG77w=; b=oAzdr1O00HIBFZMaZo7jmJ1N3OYq4Y1f/6vvuI1qte4knLSRcs1wq0YTMGBa7iPIDr BN0SXB8qiTimD1EXw5QUJyF+wkGOAYfw/RBVAlPHyXihZwZo8RI3w/xI4+LiUf1QviRE 4wHvXiEuNJ1pwmJ0GeK6eDxE/NCDCFwDmK2yxO9LYnBiXnrO4Qnwe3GrA9lzlwiDO/FT e1sZoGf44NxgK+6hmqJ0w9C87htT42pws8iPRSQ7TeRAnoE37bTwoWl5Mt59NxouPkyl AMff6MLmoRbUlodPGK3nwsnQ+XO8vLRJ/uuzxQKZ3uY7fZNVdElvs9iTTbb/Bk+IVWnz CNnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SCqmCHIn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f12si11042178jas.117.2021.05.15.03.51.25; Sat, 15 May 2021 03:51:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SCqmCHIn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233268AbhENVwp (ORCPT + 99 others); Fri, 14 May 2021 17:52:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:35476 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230247AbhENVwo (ORCPT ); Fri, 14 May 2021 17:52:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 72BDF6145B; Fri, 14 May 2021 21:51:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621029092; bh=UrQTKq6eDOpcEy53oylkG4Jq2Q9f5+I8Yceo4M4Zl+M=; h=Date:From:To:Cc:Subject:From; b=SCqmCHInnTLr81xmiVlFOGuH47epGHjG1lm1r9D1PR+yEk+H/cluUocXu7FzsJqVf GAfNUjLvLYr9GsuZBFCxGkh7ZcksKfP/aH1mn8posKFOd6ENFiGB1o+irdGwDfKGnR 3xkSpjquNHLr0LbSsSalxzDbaOIqn4g9CLrbQxQ6SlDOt9CXPROxS9r6/Nb6uEEs5a 9J2J6DxFqUoEr1myamupT6HdhQjT38XgsTd57RvnRSsGr0tXF4lkFFpfXov5nYR4Uq nTYKF0F0XYDreFWEMZsvAY3NuWN1gP/YrEMoll8XduxJe/AWugdQOA1M1veLdObnH8 DBsE12z8EVbvg== Date: Fri, 14 May 2021 16:52:09 -0500 From: "Gustavo A. R. Silva" To: Ilya Dryomov , Jeff Layton , "David S. Miller" , Jakub Kicinski Cc: ceph-devel@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] ceph: Replace zero-length array with flexible array member Message-ID: <20210514215209.GA33310@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is a regular need in the kernel to provide a way to declare having a dynamically sized set of trailing elements in a structure. Kernel code should always use “flexible array members”[1] for these cases. The older style of one-element or zero-length arrays should no longer be used[2]. Notice that, in this case, sizeof(au->reply_buf) translates to zero, becase in the original code reply_buf is a zero-length array. Now that reply_buf is transformed into a flexible array, the mentioned line of code is now replaced by a literal 0. Also, as a safeguard, explicitly assign NULL to auth->authorizer_reply_buf, as no heap is allocated for it, therefore it should not be accessible. [1] https://en.wikipedia.org/wiki/Flexible_array_member [2] https://www.kernel.org/doc/html/v5.10/process/deprecated.html#zero-length-and-one-element-arrays Signed-off-by: Gustavo A. R. Silva --- net/ceph/auth_none.c | 4 ++-- net/ceph/auth_none.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/net/ceph/auth_none.c b/net/ceph/auth_none.c index 70e86e462250..10ee16d2cbf0 100644 --- a/net/ceph/auth_none.c +++ b/net/ceph/auth_none.c @@ -111,8 +111,8 @@ static int ceph_auth_none_create_authorizer( auth->authorizer = (struct ceph_authorizer *) au; auth->authorizer_buf = au->buf; auth->authorizer_buf_len = au->buf_len; - auth->authorizer_reply_buf = au->reply_buf; - auth->authorizer_reply_buf_len = sizeof (au->reply_buf); + auth->authorizer_reply_buf_len = 0; + auth->authorizer_reply_buf = NULL; return 0; } diff --git a/net/ceph/auth_none.h b/net/ceph/auth_none.h index 4158f064302e..3c68c0ee3dab 100644 --- a/net/ceph/auth_none.h +++ b/net/ceph/auth_none.h @@ -16,7 +16,7 @@ struct ceph_none_authorizer { struct ceph_authorizer base; char buf[128]; int buf_len; - char reply_buf[0]; + char reply_buf[]; }; struct ceph_auth_none_info { -- 2.27.0