From: Alexander Aring Date: Fri, 11 Dec 2020 10:47:18 -0500 Subject: [Cluster-devel] [PATCH dlm-next 2/2] fs: dlm: transparently align name buffer In-Reply-To: <20201211154718.99346-1-aahringo@redhat.com> References: <20201211154718.99346-1-aahringo@redhat.com> Message-ID: <20201211154718.99346-3-aahringo@redhat.com> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit This patch adds a zeroed temporary buffer to align the given resource name of a dlm lock user space request transparently to a 4 byte aligned buffer. I hit the assert while running the recent pending patch which contains a 4 byte aligned assert for the dlm header msglength field. It's important that the allocation and msglength field is 4 byte aligned as the dlm_header structure is natural aligned to 4 byte values. The internal dlm allocator can return the next remaining space from a previously allocated length. The buffer will not be aligned to 4 byte anymore if this case occurs. At receiving side we cannot parse the next dlm message because the next dlm header starts at a unaligned address as well. Signed-off-by: Alexander Aring --- fs/dlm/user.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/dlm/user.c b/fs/dlm/user.c index 9f2f743eeb31..70a5116df9fe 100644 --- a/fs/dlm/user.c +++ b/fs/dlm/user.c @@ -236,6 +236,7 @@ void dlm_user_add_ast(struct dlm_lkb *lkb, uint32_t flags, int mode, static int device_user_lock(struct dlm_user_proc *proc, struct dlm_lock_params *params) { + unsigned char name[DLM_RESNAME_MAXLEN] = {}; struct dlm_ls *ls; struct dlm_user_args *ua; uint32_t lkid; @@ -270,17 +271,19 @@ static int device_user_lock(struct dlm_user_proc *proc, params->lkid, params->lvb, (unsigned long) params->timeout); } else if (params->flags & DLM_LKF_ORPHAN) { + memcpy(name, params->name, params->namelen); error = dlm_user_adopt_orphan(ls, ua, params->mode, params->flags, - params->name, params->namelen, + name, ALIGN(params->namelen, 4), (unsigned long) params->timeout, &lkid); if (!error) error = lkid; } else { + memcpy(name, params->name, params->namelen); error = dlm_user_request(ls, ua, params->mode, params->flags, - params->name, params->namelen, + name, ALIGN(params->namelen, 4), (unsigned long) params->timeout); if (!error) error = ua->lksb.sb_lkid; -- 2.26.2