return -EPERM;
        if (*ppos != 0)
                return -EINVAL;
-       if (count < SMK_NETLBLADDRMIN)
+       if (count < SMK_NETLBLADDRMIN || count > PAGE_SIZE - 1)
                return -EINVAL;
 
        data = memdup_user_nul(buf, count);
                return -EPERM;
        if (*ppos != 0)
                return -EINVAL;
-       if (count < SMK_NETLBLADDRMIN)
+       if (count < SMK_NETLBLADDRMIN || count > PAGE_SIZE - 1)
                return -EINVAL;
 
        data = memdup_user_nul(buf, count);
        if (!smack_privileged(CAP_MAC_ADMIN))
                return -EPERM;
 
+       /* Enough data must be present */
+       if (count == 0 || count > PAGE_SIZE)
+               return -EINVAL;
+
        data = memdup_user_nul(buf, count);
        if (IS_ERR(data))
                return PTR_ERR(data);
        if (!smack_privileged(CAP_MAC_ADMIN))
                return -EPERM;
 
+       if (count > PAGE_SIZE)
+               return -EINVAL;
+
        data = memdup_user_nul(buf, count);
        if (IS_ERR(data))
                return PTR_ERR(data);
        if (!smack_privileged(CAP_MAC_ADMIN))
                return -EPERM;
 
+       if (count > PAGE_SIZE)
+               return -EINVAL;
+
        data = memdup_user_nul(buf, count);
        if (IS_ERR(data))
                return PTR_ERR(data);
        if (!smack_privileged(CAP_MAC_ADMIN))
                return -EPERM;
 
+       /* Enough data must be present */
+       if (count == 0 || count > PAGE_SIZE)
+               return -EINVAL;
+
        data = memdup_user_nul(buf, count);
        if (IS_ERR(data))
                return PTR_ERR(data);
                return -EPERM;
 
        /*
+        * No partial write.
         * Enough data must be present.
         */
        if (*ppos != 0)
                return -EINVAL;
+       if (count == 0 || count > PAGE_SIZE)
+               return -EINVAL;
 
        data = memdup_user_nul(buf, count);
        if (IS_ERR(data))