LCOV - code coverage report
Current view: top level - fs/lockd - xdr.c (source / functions) Hit Total Coverage
Test: gcov_data_raspi2_real_modules_combined.info Lines: 0 140 0.0 %
Date: 2020-09-30 20:25:40 Functions: 0 18 0.0 %
Branches: 0 74 0.0 %

           Branch data     Line data    Source code
       1                 :            : // SPDX-License-Identifier: GPL-2.0
       2                 :            : /*
       3                 :            :  * linux/fs/lockd/xdr.c
       4                 :            :  *
       5                 :            :  * XDR support for lockd and the lock client.
       6                 :            :  *
       7                 :            :  * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
       8                 :            :  */
       9                 :            : 
      10                 :            : #include <linux/types.h>
      11                 :            : #include <linux/sched.h>
      12                 :            : #include <linux/nfs.h>
      13                 :            : 
      14                 :            : #include <linux/sunrpc/xdr.h>
      15                 :            : #include <linux/sunrpc/clnt.h>
      16                 :            : #include <linux/sunrpc/svc.h>
      17                 :            : #include <linux/sunrpc/stats.h>
      18                 :            : #include <linux/lockd/lockd.h>
      19                 :            : 
      20                 :            : #include <uapi/linux/nfs2.h>
      21                 :            : 
      22                 :            : #define NLMDBG_FACILITY         NLMDBG_XDR
      23                 :            : 
      24                 :            : 
      25                 :            : static inline loff_t
      26                 :            : s32_to_loff_t(__s32 offset)
      27                 :            : {
      28                 :          0 :         return (loff_t)offset;
      29                 :            : }
      30                 :            : 
      31                 :            : static inline __s32
      32                 :            : loff_t_to_s32(loff_t offset)
      33                 :            : {
      34                 :            :         __s32 res;
      35   [ #  #  #  # ]:          0 :         if (offset >= NLM_OFFSET_MAX)
      36                 :            :                 res = NLM_OFFSET_MAX;
      37   [ #  #  #  # ]:          0 :         else if (offset <= -NLM_OFFSET_MAX)
      38                 :            :                 res = -NLM_OFFSET_MAX;
      39                 :            :         else
      40                 :          0 :                 res = offset;
      41                 :            :         return res;
      42                 :            : }
      43                 :            : 
      44                 :            : /*
      45                 :            :  * XDR functions for basic NLM types
      46                 :            :  */
      47                 :          0 : static __be32 *nlm_decode_cookie(__be32 *p, struct nlm_cookie *c)
      48                 :            : {
      49                 :            :         unsigned int    len;
      50                 :            : 
      51                 :          0 :         len = ntohl(*p++);
      52                 :            :         
      53         [ #  # ]:          0 :         if(len==0)
      54                 :            :         {
      55                 :          0 :                 c->len=4;
      56                 :          0 :                 memset(c->data, 0, 4);       /* hockeypux brain damage */
      57                 :            :         }
      58         [ #  # ]:          0 :         else if(len<=NLM_MAXCOOKIELEN)
      59                 :            :         {
      60                 :          0 :                 c->len=len;
      61                 :          0 :                 memcpy(c->data, p, len);
      62                 :          0 :                 p+=XDR_QUADLEN(len);
      63                 :            :         }
      64                 :            :         else 
      65                 :            :         {
      66                 :            :                 dprintk("lockd: bad cookie size %d (only cookies under "
      67                 :            :                         "%d bytes are supported.)\n",
      68                 :            :                                 len, NLM_MAXCOOKIELEN);
      69                 :            :                 return NULL;
      70                 :            :         }
      71                 :          0 :         return p;
      72                 :            : }
      73                 :            : 
      74                 :            : static inline __be32 *
      75                 :          0 : nlm_encode_cookie(__be32 *p, struct nlm_cookie *c)
      76                 :            : {
      77                 :          0 :         *p++ = htonl(c->len);
      78                 :          0 :         memcpy(p, c->data, c->len);
      79                 :          0 :         p+=XDR_QUADLEN(c->len);
      80                 :          0 :         return p;
      81                 :            : }
      82                 :            : 
      83                 :            : static __be32 *
      84                 :          0 : nlm_decode_fh(__be32 *p, struct nfs_fh *f)
      85                 :            : {
      86                 :            :         unsigned int    len;
      87                 :            : 
      88         [ #  # ]:          0 :         if ((len = ntohl(*p++)) != NFS2_FHSIZE) {
      89                 :            :                 dprintk("lockd: bad fhandle size %d (should be %d)\n",
      90                 :            :                         len, NFS2_FHSIZE);
      91                 :            :                 return NULL;
      92                 :            :         }
      93                 :          0 :         f->size = NFS2_FHSIZE;
      94                 :          0 :         memset(f->data, 0, sizeof(f->data));
      95                 :          0 :         memcpy(f->data, p, NFS2_FHSIZE);
      96                 :          0 :         return p + XDR_QUADLEN(NFS2_FHSIZE);
      97                 :            : }
      98                 :            : 
      99                 :            : /*
     100                 :            :  * Encode and decode owner handle
     101                 :            :  */
     102                 :            : static inline __be32 *
     103                 :            : nlm_decode_oh(__be32 *p, struct xdr_netobj *oh)
     104                 :            : {
     105                 :          0 :         return xdr_decode_netobj(p, oh);
     106                 :            : }
     107                 :            : 
     108                 :            : static inline __be32 *
     109                 :            : nlm_encode_oh(__be32 *p, struct xdr_netobj *oh)
     110                 :            : {
     111                 :            :         return xdr_encode_netobj(p, oh);
     112                 :            : }
     113                 :            : 
     114                 :            : static __be32 *
     115                 :          0 : nlm_decode_lock(__be32 *p, struct nlm_lock *lock)
     116                 :            : {
     117                 :          0 :         struct file_lock        *fl = &lock->fl;
     118                 :            :         s32                     start, len, end;
     119                 :            : 
     120         [ #  # ]:          0 :         if (!(p = xdr_decode_string_inplace(p, &lock->caller,
     121                 :            :                                             &lock->len,
     122                 :            :                                             NLM_MAXSTRLEN))
     123         [ #  # ]:          0 :          || !(p = nlm_decode_fh(p, &lock->fh))
     124         [ #  # ]:          0 :          || !(p = nlm_decode_oh(p, &lock->oh)))
     125                 :            :                 return NULL;
     126                 :          0 :         lock->svid  = ntohl(*p++);
     127                 :            : 
     128                 :          0 :         locks_init_lock(fl);
     129                 :          0 :         fl->fl_flags = FL_POSIX;
     130                 :          0 :         fl->fl_type  = F_RDLCK;              /* as good as anything else */
     131                 :          0 :         start = ntohl(*p++);
     132                 :          0 :         len = ntohl(*p++);
     133                 :          0 :         end = start + len - 1;
     134                 :            : 
     135                 :          0 :         fl->fl_start = s32_to_loff_t(start);
     136                 :            : 
     137         [ #  # ]:          0 :         if (len == 0 || end < 0)
     138                 :          0 :                 fl->fl_end = OFFSET_MAX;
     139                 :            :         else
     140                 :          0 :                 fl->fl_end = s32_to_loff_t(end);
     141                 :          0 :         return p;
     142                 :            : }
     143                 :            : 
     144                 :            : /*
     145                 :            :  * Encode result of a TEST/TEST_MSG call
     146                 :            :  */
     147                 :            : static __be32 *
     148                 :          0 : nlm_encode_testres(__be32 *p, struct nlm_res *resp)
     149                 :            : {
     150                 :            :         s32             start, len;
     151                 :            : 
     152         [ #  # ]:          0 :         if (!(p = nlm_encode_cookie(p, &resp->cookie)))
     153                 :            :                 return NULL;
     154                 :          0 :         *p++ = resp->status;
     155                 :            : 
     156         [ #  # ]:          0 :         if (resp->status == nlm_lck_denied) {
     157                 :            :                 struct file_lock        *fl = &resp->lock.fl;
     158                 :            : 
     159         [ #  # ]:          0 :                 *p++ = (fl->fl_type == F_RDLCK)? xdr_zero : xdr_one;
     160                 :          0 :                 *p++ = htonl(resp->lock.svid);
     161                 :            : 
     162                 :            :                 /* Encode owner handle. */
     163         [ #  # ]:          0 :                 if (!(p = xdr_encode_netobj(p, &resp->lock.oh)))
     164                 :            :                         return NULL;
     165                 :            : 
     166                 :          0 :                 start = loff_t_to_s32(fl->fl_start);
     167         [ #  # ]:          0 :                 if (fl->fl_end == OFFSET_MAX)
     168                 :            :                         len = 0;
     169                 :            :                 else
     170                 :          0 :                         len = loff_t_to_s32(fl->fl_end - fl->fl_start + 1);
     171                 :            : 
     172                 :          0 :                 *p++ = htonl(start);
     173                 :          0 :                 *p++ = htonl(len);
     174                 :            :         }
     175                 :            : 
     176                 :          0 :         return p;
     177                 :            : }
     178                 :            : 
     179                 :            : 
     180                 :            : /*
     181                 :            :  * First, the server side XDR functions
     182                 :            :  */
     183                 :            : int
     184                 :          0 : nlmsvc_decode_testargs(struct svc_rqst *rqstp, __be32 *p)
     185                 :            : {
     186                 :          0 :         struct nlm_args *argp = rqstp->rq_argp;
     187                 :            :         u32     exclusive;
     188                 :            : 
     189         [ #  # ]:          0 :         if (!(p = nlm_decode_cookie(p, &argp->cookie)))
     190                 :            :                 return 0;
     191                 :            : 
     192                 :          0 :         exclusive = ntohl(*p++);
     193         [ #  # ]:          0 :         if (!(p = nlm_decode_lock(p, &argp->lock)))
     194                 :            :                 return 0;
     195         [ #  # ]:          0 :         if (exclusive)
     196                 :          0 :                 argp->lock.fl.fl_type = F_WRLCK;
     197                 :            : 
     198                 :          0 :         return xdr_argsize_check(rqstp, p);
     199                 :            : }
     200                 :            : 
     201                 :            : int
     202                 :          0 : nlmsvc_encode_testres(struct svc_rqst *rqstp, __be32 *p)
     203                 :            : {
     204                 :          0 :         struct nlm_res *resp = rqstp->rq_resp;
     205                 :            : 
     206         [ #  # ]:          0 :         if (!(p = nlm_encode_testres(p, resp)))
     207                 :            :                 return 0;
     208                 :          0 :         return xdr_ressize_check(rqstp, p);
     209                 :            : }
     210                 :            : 
     211                 :            : int
     212                 :          0 : nlmsvc_decode_lockargs(struct svc_rqst *rqstp, __be32 *p)
     213                 :            : {
     214                 :          0 :         struct nlm_args *argp = rqstp->rq_argp;
     215                 :            :         u32     exclusive;
     216                 :            : 
     217         [ #  # ]:          0 :         if (!(p = nlm_decode_cookie(p, &argp->cookie)))
     218                 :            :                 return 0;
     219                 :          0 :         argp->block  = ntohl(*p++);
     220                 :          0 :         exclusive    = ntohl(*p++);
     221         [ #  # ]:          0 :         if (!(p = nlm_decode_lock(p, &argp->lock)))
     222                 :            :                 return 0;
     223         [ #  # ]:          0 :         if (exclusive)
     224                 :          0 :                 argp->lock.fl.fl_type = F_WRLCK;
     225                 :          0 :         argp->reclaim = ntohl(*p++);
     226                 :          0 :         argp->state   = ntohl(*p++);
     227                 :          0 :         argp->monitor = 1;           /* monitor client by default */
     228                 :            : 
     229                 :          0 :         return xdr_argsize_check(rqstp, p);
     230                 :            : }
     231                 :            : 
     232                 :            : int
     233                 :          0 : nlmsvc_decode_cancargs(struct svc_rqst *rqstp, __be32 *p)
     234                 :            : {
     235                 :          0 :         struct nlm_args *argp = rqstp->rq_argp;
     236                 :            :         u32     exclusive;
     237                 :            : 
     238         [ #  # ]:          0 :         if (!(p = nlm_decode_cookie(p, &argp->cookie)))
     239                 :            :                 return 0;
     240                 :          0 :         argp->block = ntohl(*p++);
     241                 :          0 :         exclusive = ntohl(*p++);
     242         [ #  # ]:          0 :         if (!(p = nlm_decode_lock(p, &argp->lock)))
     243                 :            :                 return 0;
     244         [ #  # ]:          0 :         if (exclusive)
     245                 :          0 :                 argp->lock.fl.fl_type = F_WRLCK;
     246                 :          0 :         return xdr_argsize_check(rqstp, p);
     247                 :            : }
     248                 :            : 
     249                 :            : int
     250                 :          0 : nlmsvc_decode_unlockargs(struct svc_rqst *rqstp, __be32 *p)
     251                 :            : {
     252                 :          0 :         struct nlm_args *argp = rqstp->rq_argp;
     253                 :            : 
     254         [ #  # ]:          0 :         if (!(p = nlm_decode_cookie(p, &argp->cookie))
     255         [ #  # ]:          0 :          || !(p = nlm_decode_lock(p, &argp->lock)))
     256                 :            :                 return 0;
     257                 :          0 :         argp->lock.fl.fl_type = F_UNLCK;
     258                 :          0 :         return xdr_argsize_check(rqstp, p);
     259                 :            : }
     260                 :            : 
     261                 :            : int
     262                 :          0 : nlmsvc_decode_shareargs(struct svc_rqst *rqstp, __be32 *p)
     263                 :            : {
     264                 :          0 :         struct nlm_args *argp = rqstp->rq_argp;
     265                 :          0 :         struct nlm_lock *lock = &argp->lock;
     266                 :            : 
     267                 :          0 :         memset(lock, 0, sizeof(*lock));
     268                 :          0 :         locks_init_lock(&lock->fl);
     269                 :          0 :         lock->svid = ~(u32) 0;
     270                 :            : 
     271         [ #  # ]:          0 :         if (!(p = nlm_decode_cookie(p, &argp->cookie))
     272         [ #  # ]:          0 :          || !(p = xdr_decode_string_inplace(p, &lock->caller,
     273                 :            :                                             &lock->len, NLM_MAXSTRLEN))
     274         [ #  # ]:          0 :          || !(p = nlm_decode_fh(p, &lock->fh))
     275         [ #  # ]:          0 :          || !(p = nlm_decode_oh(p, &lock->oh)))
     276                 :            :                 return 0;
     277                 :          0 :         argp->fsm_mode = ntohl(*p++);
     278                 :          0 :         argp->fsm_access = ntohl(*p++);
     279                 :          0 :         return xdr_argsize_check(rqstp, p);
     280                 :            : }
     281                 :            : 
     282                 :            : int
     283                 :          0 : nlmsvc_encode_shareres(struct svc_rqst *rqstp, __be32 *p)
     284                 :            : {
     285                 :          0 :         struct nlm_res *resp = rqstp->rq_resp;
     286                 :            : 
     287         [ #  # ]:          0 :         if (!(p = nlm_encode_cookie(p, &resp->cookie)))
     288                 :            :                 return 0;
     289                 :          0 :         *p++ = resp->status;
     290                 :          0 :         *p++ = xdr_zero;                /* sequence argument */
     291                 :          0 :         return xdr_ressize_check(rqstp, p);
     292                 :            : }
     293                 :            : 
     294                 :            : int
     295                 :          0 : nlmsvc_encode_res(struct svc_rqst *rqstp, __be32 *p)
     296                 :            : {
     297                 :          0 :         struct nlm_res *resp = rqstp->rq_resp;
     298                 :            : 
     299         [ #  # ]:          0 :         if (!(p = nlm_encode_cookie(p, &resp->cookie)))
     300                 :            :                 return 0;
     301                 :          0 :         *p++ = resp->status;
     302                 :          0 :         return xdr_ressize_check(rqstp, p);
     303                 :            : }
     304                 :            : 
     305                 :            : int
     306                 :          0 : nlmsvc_decode_notify(struct svc_rqst *rqstp, __be32 *p)
     307                 :            : {
     308                 :          0 :         struct nlm_args *argp = rqstp->rq_argp;
     309                 :            :         struct nlm_lock *lock = &argp->lock;
     310                 :            : 
     311         [ #  # ]:          0 :         if (!(p = xdr_decode_string_inplace(p, &lock->caller,
     312                 :            :                                             &lock->len, NLM_MAXSTRLEN)))
     313                 :            :                 return 0;
     314                 :          0 :         argp->state = ntohl(*p++);
     315                 :          0 :         return xdr_argsize_check(rqstp, p);
     316                 :            : }
     317                 :            : 
     318                 :            : int
     319                 :          0 : nlmsvc_decode_reboot(struct svc_rqst *rqstp, __be32 *p)
     320                 :            : {
     321                 :          0 :         struct nlm_reboot *argp = rqstp->rq_argp;
     322                 :            : 
     323         [ #  # ]:          0 :         if (!(p = xdr_decode_string_inplace(p, &argp->mon, &argp->len, SM_MAXSTRLEN)))
     324                 :            :                 return 0;
     325                 :          0 :         argp->state = ntohl(*p++);
     326                 :          0 :         memcpy(&argp->priv.data, p, sizeof(argp->priv.data));
     327                 :          0 :         p += XDR_QUADLEN(SM_PRIV_SIZE);
     328                 :          0 :         return xdr_argsize_check(rqstp, p);
     329                 :            : }
     330                 :            : 
     331                 :            : int
     332                 :          0 : nlmsvc_decode_res(struct svc_rqst *rqstp, __be32 *p)
     333                 :            : {
     334                 :          0 :         struct nlm_res *resp = rqstp->rq_argp;
     335                 :            : 
     336         [ #  # ]:          0 :         if (!(p = nlm_decode_cookie(p, &resp->cookie)))
     337                 :            :                 return 0;
     338                 :          0 :         resp->status = *p++;
     339                 :          0 :         return xdr_argsize_check(rqstp, p);
     340                 :            : }
     341                 :            : 
     342                 :            : int
     343                 :          0 : nlmsvc_decode_void(struct svc_rqst *rqstp, __be32 *p)
     344                 :            : {
     345                 :          0 :         return xdr_argsize_check(rqstp, p);
     346                 :            : }
     347                 :            : 
     348                 :            : int
     349                 :          0 : nlmsvc_encode_void(struct svc_rqst *rqstp, __be32 *p)
     350                 :            : {
     351                 :          0 :         return xdr_ressize_check(rqstp, p);
     352                 :            : }

Generated by: LCOV version 1.14